結果
| 問題 |
No.2898 Update Max
|
| コンテスト | |
| ユーザー |
chro_96
|
| 提出日時 | 2024-09-20 23:02:33 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,861 bytes |
| コンパイル時間 | 275 ms |
| コンパイル使用メモリ | 31,360 KB |
| 実行使用メモリ | 5,760 KB |
| 最終ジャッジ日時 | 2024-09-20 23:02:37 |
| 合計ジャッジ時間 | 1,909 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 8 WA * 20 |
ソースコード
#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;
}
}
return ans;
}
int main () {
int n = 0;
int a[200000] = {};
int res = 0;
long long ans = 0LL;
long long mod_num = 998244353LL;
int btotal = 0;
int bcnt = 0;
int max = 0;
long long fact[200001] = {};
long long invf[200001] = {};
res = scanf("%d", &n);
for (int i = 0; i < n; i++) {
res = scanf("%d", a+i);
if (a[i] < 0) {
btotal++;
}
}
fact[0] = 1LL;
for (int i = 0; i < n; i++) {
fact[i+1] = fact[i];
fact[i+1] *= (long long)(i+1);
fact[i+1] %= mod_num;
}
invf[n] = power_mod(fact[n], mod_num-2LL, mod_num);
for (int i = n; i > 0; i--) {
invf[i-1] = invf[i];
invf[i-1] *= (long long)i;
invf[i-1] %= mod_num;
}
for (int i = 0; i < n; i++) {
if (a[i] < 0) {
long long tmp = fact[btotal];
tmp *= invf[bcnt+1];
tmp %= mod_num;
tmp *= fact[bcnt];
ans += tmp;
ans %= mod_num;
if (i < max) {
long long tmp = fact[bcnt+max-i];
tmp *= invf[bcnt+1];
tmp %= mod_num;
tmp *= invf[max-i-1];
tmp %= mod_num;
tmp *= fact[bcnt];
tmp %= mod_num;
tmp *= fact[btotal-bcnt-1];
ans += mod_num-tmp%mod_num;
ans %= mod_num;
}
bcnt++;
} else if (a[i] > max) {
if (a[i] > i) {
long long tmp = fact[a[i]-1-i+bcnt];
tmp %= mod_num;
tmp *= invf[a[i]-1-i];
tmp %= mod_num;
tmp *= fact[btotal-bcnt];
ans += tmp;
ans %= mod_num;
}
max = a[i];
}
}
printf("%lld\n", ans);
return 0;
}
chro_96