結果

問題 No.1443 Andd
ユーザー simansiman
提出日時 2022-01-04 05:38:16
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,071 bytes
コンパイル時間 7,555 ms
コンパイル使用メモリ 143,080 KB
実行使用メモリ 45,952 KB
最終ジャッジ日時 2024-04-21 21:01:31
合計ジャッジ時間 5,256 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 6 ms
5,376 KB
testcase_04 AC 8 ms
5,376 KB
testcase_05 AC 6 ms
5,376 KB
testcase_06 AC 6 ms
5,376 KB
testcase_07 AC 8 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 8 ms
5,504 KB
testcase_11 AC 8 ms
5,376 KB
testcase_12 AC 8 ms
5,376 KB
testcase_13 AC 35 ms
13,952 KB
testcase_14 AC 36 ms
13,824 KB
testcase_15 AC 36 ms
13,952 KB
testcase_16 AC 35 ms
13,824 KB
testcase_17 AC 36 ms
13,824 KB
testcase_18 AC 137 ms
45,824 KB
testcase_19 AC 138 ms
45,952 KB
testcase_20 AC 134 ms
45,952 KB
testcase_21 AC 135 ms
45,824 KB
testcase_22 AC 133 ms
45,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  vector<int> RUI = A;
  RUI.push_back(0);

  for (int i = N - 1; i >= 0; --i) {
    RUI[i] += RUI[i + 1];
  }

  bool dp[N + 1][2][1024];
  memset(dp, false, sizeof(dp));
  dp[0][1][0] = true;
  int ans = 1;
  vector<bool> memo(N * 1024, false);
  memo[RUI[0]] = true;

  for (int i = 0; i < N; ++i) {
    int a = A[i];

    for (int k = 0; k < 1024; ++k) {
      if (!dp[i][0][k] && !dp[i][1][k]) continue;

      dp[i + 1][0][(k + a) % 1024] = true;
      dp[i + 1][1][k & a] = true;
    }

    for (int k = 0; k < 1024; ++k) {
      if (not dp[i + 1][1][k]) continue;
      int v = k + RUI[i + 1];

      if (memo[v]) continue;
      memo[v] = true;
      ++ans;
    }

    cout << ans << endl;
  }

  return 0;
}
0