結果
問題 | No.2144 MM |
ユーザー |
|
提出日時 | 2023-01-28 22:47:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 753 bytes |
コンパイル時間 | 433 ms |
コンパイル使用メモリ | 67,092 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-06-29 00:08:49 |
合計ジャッジ時間 | 1,914 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 10 WA * 25 |
ソースコード
#include <iostream> #include <algorithm> using namespace std; const long long md = 998244353; int c[200009]; long long d[200009][2]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; d[n][0] = 1; for (int i = n - 1; i >= 1; i--) { if (i & 1) c[i] = m - 1; d[i][0] = ((d[i + 1][1]) * (m - 1)) % md; d[i][1] = (d[i + 1][1] * (m - 2) + d[i + 1][0]) % md; } int s = 0; long long ans = 1; for (int i = 1; i <= n; i++) { int a; cin >> a; if (i & 1) s = (s + a) % m; else s = (s - a + m) % m; int ds = (s - c[i] + m) % m; if (0 < ds && ds <= a) ans = (ans + d[i][0] + d[i][1] * (a - 1)) % md; else ans = (ans + d[i][1] * a) % md; } if (s) cout << -1 << '\n'; else cout << ans << '\n'; return 0; }