萌新刚学OI1秒,不知道为什么厌氧,求调QAQ
查看原帖
萌新刚学OI1秒,不知道为什么厌氧,求调QAQ
539200
Trump_楼主2023/9/21 20:55
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map>

using std::cin;
using std::cout;
using std::endl;

int m, n, k;
bool dp[2][110];
int a[1000400], now, next = 1;

int main() {
    scanf("%d", &m);
    while (m --) {
        now = 0, next = 1;
        scanf("%d%d", &n, &k);
        for (int i = 1, num; i <= n; ++ i) {
            scanf("%d", &num);   
            a[i] = (num % k + k) % k;
            // cout << a[i] << " " << endl;
        }
        dp[now][0] = true;
        for (int i = 1; i <= n; ++ i) {
            for (int j = 0; j <= k; ++ j) {
                if (dp[now][j] == 0) continue;
                // cout << dp[now][j] << " " << j << endl;
                dp[next][(j + a[i] + k) % k] = dp[now][j];
                dp[next][(j - a[i] + k) % k] = dp[now][j];
            }
            for (int j = 0; j <= k; ++ j) {
                dp[now][j] = 0;
            }
            now ^= 1;
            next ^= 1;
        }
        if (dp[now][0] != 0) cout << "Divisible" << endl;
        else cout << "Not divisible" << endl;
        for (int j = 0; j <= n; ++ j) {
            dp[now][j] = dp[next][j] = 0;
        }
    }
}
2023/9/21 20:55
加载中...