結果

問題 No.1444 !Andd
ユーザー iaNTU
提出日時 2021-01-22 15:23:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 724 bytes
コンパイル時間 1,780 ms
コンパイル使用メモリ 191,928 KB
最終ジャッジ日時 2025-01-18 03:20:08
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 5 RE * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:13:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
      |                                      ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

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

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

int a[kN];
bool now[kN][kC], dp[kN][kC];

int main() {
	int n, ans = 1;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	
	now[0][0] = true;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < kC; j++) if (now[i - 1][j]) dp[i][j & a[i]] = true;
		for (int j = 0; j < kC; j++) if (dp[i][j]) ans++;
		if (now[i - 1][0] && dp[i][a[i]]) ans--;
		for (int j = a[i]; j < kC; j++) if (now[i - 1][j - a[i]]) now[i][j] = true;
		for (int j = 0; j < a[i]; j++) if (now[i - 1][j + kC - a[i]]) now[i][j] = true;
		for (int j = 0; j < kC; j++) if (dp[i][j]) now[i][j] = true;
	}
	
	printf("%d\n", ans);
}
0