結果
問題 | No.2144 MM |
ユーザー |
![]() |
提出日時 | 2022-12-02 23:18:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,171 bytes |
コンパイル時間 | 4,345 ms |
コンパイル使用メモリ | 254,164 KB |
最終ジャッジ日時 | 2025-02-09 04:25:15 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 16 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i<n; i++) #define repx(i, l, n) for(int i=l; i<n; i++) #define all(v) v.begin(), v.end() #define show(x) cout << #x << ": " << x << endl; #define list(x) cout << #x << ": " << x << " "; #define pb push_back using vi = vector<lint>; using vvi = vector<vector<lint>>; template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> inline void drop(T x) { cout << x << endl; exit(0); } template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; using mint = modint998244353; using vm = vector<mint>; int solve(lint N, lint M, vi v) { lint a=0, b=0, c=0, x, y, z; rep(i, N-1) { x = (M-v[i])%M; v[i] += x; v[i+1] += x; } if (v[N-1]%M == 0) return 1; else return 0; } int main() { lint N, M; cin >> N >> M; vi v(N); vin(v); mint a=0, b=0, c=0; lint x=0, y=0, z=0; if (!solve(N, M, v)) drop(-1); vm dpo(3), dpe(3); rep(i, N) { z = v[i]; if (i%2 == 0) { y = x+v[i]; a = dpo[0]+dpo[1]+dpo[2]; dpe[0] = a-dpo[1]; dpe[1] = a*(M-2)-dpo[2]; dpe[2] = a-dpo[0]; if ((x <= 0 && 0 < y) || (x <= M && M < y)) dpe[0]++, z--; if ((x <= M-1 && M-1 < y) || (x <= M+M-1 && M+M-1 < y)) dpe[2]++, z--; dpe[1] += z; x += v[i]; } else { y = x-v[i]; a = dpe[0]+dpe[1]+dpe[2]; dpo[0] = a-dpe[2]; dpo[1] = a-dpe[0]; dpo[2] = a*(M-2)-dpe[1]; if ((y < 0 && 0 <= x) || (y < -M && -M <= x)) dpo[0]++, z--; if ((y < 1 && 1 <= x) || (y < -M+1 && -M+1 <= x)) dpo[1]++, z--; dpo[2] += z; x -= v[i]; } x = (x+M)%M; // list(dpe[0].val()) // list(dpe[1].val()) // list(dpe[2].val()) // list(dpo[0].val()) // list(dpo[1].val()) // show(dpo[2].val()) } if (M%2 == 1) std::cout << dpe[0].val()+1 << '\n'; if (M%2 == 0) std::cout << dpo[0].val()+1 << '\n'; }