結果
問題 |
No.3041 非対称じゃんけん
|
ユーザー |
![]() |
提出日時 | 2025-03-04 19:17:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,186 ms / 2,200 ms |
コード長 | 1,634 bytes |
コンパイル時間 | 2,282 ms |
コンパイル使用メモリ | 198,056 KB |
実行使用メモリ | 8,604 KB |
最終ジャッジ日時 | 2025-03-04 19:17:36 |
合計ジャッジ時間 | 10,169 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; static inline void shift_or(const vector<uint64_t>& dp, vector<uint64_t>& ndp, int s, int nb) { int off = s >> 6; int r = s & 63; for (int i = nb - 1; i >= 0; i--) { uint64_t v = 0; int j = i - off; if(j >= 0) v |= dp[j] << r; if(r && j - 1 >= 0) v |= dp[j - 1] >> (64 - r); ndp[i] |= v; } } static inline int count_bits(const vector<uint64_t>& dp, int L) { int nb = L >> 6; int rem = L & 63; int cnt = 0; for (int i = 0; i < nb; i++) cnt += __builtin_popcountll(dp[i]); if(rem) { uint64_t mask = (1ULL << rem) - 1; cnt += __builtin_popcountll(dp[nb] & mask); } return cnt; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, F; cin >> N >> F; vector<int> A(N), B(N), C(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; for (int i = 0; i < N; i++) cin >> C[i]; int max_sum = N * F; int maxBlock = (max_sum + 1 + 63) >> 6; vector<uint64_t> dp(maxBlock, 0), ndp(maxBlock, 0); dp[0] = 1; int cur = 0; for (int i = 0; i < N; i++){ cur += F; int L = cur + 1; int nb = (L + 63) >> 6; memset(ndp.data(), 0, nb * sizeof(uint64_t)); shift_or(dp, ndp, A[i], nb); shift_or(dp, ndp, B[i], nb); shift_or(dp, ndp, C[i], nb); int rem = L & 63; if(rem) ndp[nb - 1] &= ((uint64_t)1 << rem) - 1; for (int j = 0; j < nb; j++) dp[j] = ndp[j]; cout << count_bits(dp, L) << endl; } return 0; }