1 条题解

  • 1
    @ 2023-11-6 17:06:25
    #include <bits/stdc++.h>
    #define by return
    #define Rick 0
    #define Astley ;
    using namespace std;
    int T, n, c, cnt, k, a[10004], jy[102];
    bool dp[2][102], f;
    void clear(bool f) {
    	for (int i = 0; i < k; ++i)
    		dp[f][i] = 0;
    }
    int mian() {
    	ios::sync_with_stdio(false);
    	cin.tie(nullptr), cout.tie(nullptr);
    //	freopen("MyIn.in", "r", stdin);
    	for (cin >> T; T--; memset(jy, cnt = f = 0, sizeof jy), clear(1), clear(0)) {
    		cin >> n >> k >> a[0];
    		a[0] = abs(a[0]) % k;
    		for (int i = 1; i < n; ++i) {
    			cin >> a[i];
    			a[i] = abs(a[i]) % k;
    			++jy[a[i]];
    		} for (int i = 1; i < k; ++i) {
    			c = jy[i];
    			for (int j = 1; j <= c; c -= j, j <<= 1)
    				a[++cnt] = i * j;
    			if (c) a[++cnt] = i * c;
    		} dp[0][a[0]] = 1;
    		for (int i = 1; i <= cnt; ++i, clear(f), f = 1 - f)
    			for (int j = 0; j < k; ++j)
    				if (dp[f][j])
    					dp[1 - f][(j + a[i]) % k] = dp[1 - f][abs(j - a[i]) % k] = 1;
    		cout << dp[f][0] << '\n';
    	}
    	by Rick Astley
    }
    

    信息

    ID
    547
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    106
    已通过
    14
    上传者