結果

問題 No.1444 !Andd
コンテスト
ユーザー iaNTU
提出日時 2021-01-22 15:17:35
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 844 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,591 ms
コンパイル使用メモリ 213,944 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-17 05:28:57
合計ジャッジ時間 3,775 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 5 RE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

constexpr int kN = int(5E3 + 10);
constexpr int kC = 1 << 10;

int a[kN];
bitset<kC> now, cur;

int main() {
	int n, ans = 1;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

	now[0] = true;
	for (int i = 1; i <= n; i++) {
		cur.reset();
		int rev = kC - 1 - a[i];
		for (int j = a[i]; j > 0; j = (j - 1) & a[i]) {
			if (now.test(j)) {
				cur[j] = true;
				continue;
			}
			for (int k = rev; k > 0; k = (k - 1) & rev) if (now.test(j | k)) {
				cur[j] = true;
				break;
			}
		}
		if (now.test(0)) cur[0] = true;
		else {
			for (int k = rev; k > 0; k = (k - 1) & rev) if (now.test(k)) {
				cur[0] = true;
				break;
			}
		}
		ans += cur.count();
		if (now.test(0) && cur.test(a[i])) ans--;
		now = (now << a[i]) | (now >> (kC - a[i])) | cur;
	}
	printf("%d\n", ans);
}
0