結果
問題 | No.2653 [Cherry 6th Tune] Re: start! (Make it Zero!) |
ユーザー | chro_96 |
提出日時 | 2024-02-23 23:32:43 |
言語 | C (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,123 bytes |
コンパイル時間 | 847 ms |
コンパイル使用メモリ | 33,280 KB |
実行使用メモリ | 7,500 KB |
最終ジャッジ日時 | 2024-09-29 09:05:34 |
合計ジャッジ時間 | 8,717 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
7,364 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 111 ms
7,284 KB |
testcase_09 | AC | 122 ms
7,256 KB |
testcase_10 | AC | 114 ms
7,280 KB |
testcase_11 | AC | 92 ms
7,136 KB |
testcase_12 | AC | 102 ms
7,324 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | AC | 86 ms
7,320 KB |
testcase_54 | AC | 97 ms
7,196 KB |
testcase_55 | AC | 55 ms
7,180 KB |
testcase_56 | AC | 82 ms
7,288 KB |
testcase_57 | AC | 90 ms
7,312 KB |
testcase_58 | AC | 51 ms
7,212 KB |
testcase_59 | AC | 58 ms
7,264 KB |
testcase_60 | AC | 99 ms
7,292 KB |
testcase_61 | AC | 109 ms
7,364 KB |
testcase_62 | AC | 86 ms
7,280 KB |
testcase_63 | AC | 27 ms
7,264 KB |
testcase_64 | AC | 27 ms
7,340 KB |
testcase_65 | AC | 27 ms
7,320 KB |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
testcase_70 | WA | - |
testcase_71 | WA | - |
ソースコード
#include <stdio.h> long long power_mod (long long a, long long b, long long mod_num) { long long ans = 1LL; if (b > 0LL) { ans = power_mod(a, b/2LL, mod_num); ans = (ans * ans) % mod_num; if (b%2LL == 1LL) { ans = (ans * (a % mod_num)) % mod_num; } } return ans; } int main () { int t = 0; int n = 0; long long m = 0LL; int x[200000] = {}; int res = 0; long long mod_num = 998244353LL; long long pow[200001] = {}; int cnt[200001][2] = {}; long long sum[200001][2] = {}; res = scanf("%d", &t); while (t > 0) { long long ans = 0LL; res = scanf("%d", &n); res = scanf("%lld", &m); for (int i = 0; i < n; i++) { res = scanf("%d", x+i); } for (int i = 0; i < n; i++) { cnt[i+1][0] = cnt[i][0]; sum[i+1][0] = sum[i][0]; if (x[i] < 0) { cnt[i+1][0]++; } else { sum[i+1][0] += (long long)(x[i]); } } if (sum[n][0]%m != 0LL && cnt[n][0] <= 0) { printf("0\n"); } else if (cnt[n][0] <= 0) { ans = (long long)(n-1); for (int i = 0; i < n-1; i++) { if (sum[i+1][0]%m == 0LL) { ans -= 1LL; } } printf("%lld\n", ans%mod_num); } else { ans = power_mod(m, (long long)(cnt[n][0]-1), mod_num); ans *= (long long)(n-1); ans %= mod_num; for (int i = n-1; i >= 0; i--) { cnt[i][1] = cnt[i+1][1]; sum[i][1] = sum[i+1][1]; if (x[i] < 0) { cnt[i][1]++; } else { sum[i][1] += (long long)x[i]; } } for (int i = 0; i < n-1; i++) { if (cnt[i+1][0] <= 0 && sum[i+1][0]%m == 0LL) { ans += mod_num-power_mod(m, (long long)(cnt[i][1]-1), mod_num); } else if (cnt[i+1][1] <= 0 && sum[i+1][1]%m == 0LL) { ans += mod_num-power_mod(m, (long long)(cnt[i+1][0]-1), mod_num); } else if (cnt[i+1][0] > 0 && cnt[i+1][1] > 0) { ans += mod_num-power_mod(m, (long long)(cnt[i+1][0]+cnt[i+1][1]-2), mod_num); } } printf("%lld\n", ans%mod_num); } t--; } return 0; }