結果
問題 |
No.2279 OR Insertion
|
ユーザー |
|
提出日時 | 2024-01-08 18:22:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 864 bytes |
コンパイル時間 | 705 ms |
コンパイル使用メモリ | 73,316 KB |
実行使用メモリ | 128,896 KB |
最終ジャッジ日時 | 2024-09-27 19:38:39 |
合計ジャッジ時間 | 7,505 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 1 |
other | AC * 6 WA * 42 |
ソースコード
#include <iostream> #include <vector> const int P = 998244353; int main() { int N; std::cin >> N; std::vector<std::vector<long long>> A(N+1, std::vector<long long>(N)); std::vector<long long> B(N), p(N); std::string S; std::cin >> S; // Precompute powers of 2 modulo P p[0] = 1; for (int i = 1; i < N; i++) { p[i] = (p[i-1] * 2) % P; } for (int i = 1; i <= N; i++) { bool s = S[N-i] > '0'; for (int j = 0; j < i; j++) { B[j] = (B[j] + (s && j > 0 ? (p[std::max(0, i-j-2)] - A[i-j-1][j] + P) % P : 0)) % P; A[i][j] = (A[i-1][j] + (s ? (j == 0 ? p[std::max(0, i-2)] : B[j]) : 0)) % P; } } long long result = 0; for (int j = 0; j < N; j++) { result = (result + p[j] * A[N][j]) % P; } std::cout << result << std::endl; return 0; }