結果

問題 No.2144 MM
ユーザー kabipoyokabipoyo
提出日時 2022-12-02 23:15:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,046 bytes
コンパイル時間 4,400 ms
コンパイル使用メモリ 257,452 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-18 08:31:40
合計ジャッジ時間 6,415 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 58 ms
6,940 KB
testcase_08 AC 63 ms
6,940 KB
testcase_09 AC 59 ms
6,944 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 62 ms
6,940 KB
testcase_13 WA -
testcase_14 AC 66 ms
6,944 KB
testcase_15 AC 58 ms
6,940 KB
testcase_16 AC 18 ms
6,940 KB
testcase_17 AC 45 ms
6,940 KB
testcase_18 AC 18 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 43 ms
6,940 KB
testcase_21 AC 32 ms
6,940 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 14 ms
6,944 KB
testcase_25 WA -
testcase_26 AC 2 ms
6,940 KB
testcase_27 WA -
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 WA -
testcase_31 AC 2 ms
6,944 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 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;
	rep(i, N) {
		if (i%2) y += v[i];
		else z += v[i];
	}
	if (abs(y-z)%M != 0) 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[2] = a-dpo[0];
			dpe[1] = a*(M-2)-dpo[2];
			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';
}
0