Submission #60593797
Source Code Expand
Copy
#include <iostream>using namespace std;#define int long longconst int mod = 998244353;const int N = 2e5 + 7;int n, a[N], s[N], f[N], fac[N], invfac[N];int qpow(int a, int b) {int ret = 1;while(b) {if(b & 1) ret = 1ll * ret * a % mod;a = 1ll * a * a % mod;b >>= 1;}return ret;}void solve() {cin >> n;for(int i = 1; i <= n; i++) cin >> a[i];bool flag = true;for(int i = 1; i < n; i++) if((a[i] != i % 2) && (a[i + 1] != (i + 1) % 2)) flag = false;fac[0] = fac[1] = 1;
#include <iostream> using namespace std; #define int long long const int mod = 998244353; const int N = 2e5 + 7; int n, a[N], s[N], f[N], fac[N], invfac[N]; int qpow(int a, int b) { int ret = 1; while(b) { if(b & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod; b >>= 1; } return ret; } void solve() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; bool flag = true; for(int i = 1; i < n; i++) if((a[i] != i % 2) && (a[i + 1] != (i + 1) % 2)) flag = false; fac[0] = fac[1] = 1; for(int i = 2; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod; for(int i = 1; i <= n; i++) invfac[i] = qpow(fac[i], mod - 2); f[0] = 1; for(int i = 1; i <= n; i++) { for(int j = 0; j <= i; j++) { f[i] = (f[i] + 1ll * f[i - j] * invfac[j] % mod) % mod; } } if(!flag || (a[1] != 1) || (a[n] != n % 2)) { puts("0"); return; } int ans = 1, all = 0; // cout << 1ll * fac[5] * f[5] % mod << endl; for(int i = 1, j; i <= n; i = j) { j = i; if(a[j] % 2 == (j % 2)) {j ++ ; continue;} int cnt = 1; while(j + 2 <= n && a[j + 2] != (j + 2) % 2) j += 2, cnt ++ ; // cout << i << " " << "cnt = " << cnt << endl; ans = 1ll * ans * f[cnt] % mod; all += cnt; j ++ ; } ans = 1ll * ans * fac[all] % mod; cout << ans << endl; return; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; T = 1; for(int _ = 1; _ <= T; _ ++) solve(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Reversi 2 |
User | lx_zjk |
Language | C++ 20 (gcc 12.2) |
Score | 0 |
Code Size | 1637 Byte |
Status | WA |
Exec Time | 2211 ms |
Memory | 8280 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_00.txt, example_01.txt |
All | example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_00.txt | AC | 1 ms | 3488 KB |
example_01.txt | AC | 1 ms | 3608 KB |
test_00.txt | TLE | 2207 ms | 7512 KB |
test_01.txt | WA | 275 ms | 3892 KB |
test_02.txt | TLE | 2207 ms | 7848 KB |
test_03.txt | TLE | 2207 ms | 7560 KB |
test_04.txt | TLE | 2207 ms | 6768 KB |
test_05.txt | TLE | 2207 ms | 7592 KB |
test_06.txt | TLE | 2207 ms | 5780 KB |
test_07.txt | TLE | 2207 ms | 5384 KB |
test_08.txt | TLE | 2208 ms | 6840 KB |
test_09.txt | TLE | 2210 ms | 5768 KB |
test_10.txt | TLE | 2208 ms | 7668 KB |
test_11.txt | TLE | 2208 ms | 8116 KB |
test_12.txt | TLE | 2207 ms | 5612 KB |
test_13.txt | TLE | 2207 ms | 7996 KB |
test_14.txt | TLE | 2207 ms | 7156 KB |
test_15.txt | TLE | 2208 ms | 7080 KB |
test_16.txt | AC | 1420 ms | 4600 KB |
test_17.txt | AC | 12 ms | 3552 KB |
test_18.txt | TLE | 2207 ms | 4728 KB |
test_19.txt | TLE | 2207 ms | 4832 KB |
test_20.txt | TLE | 2207 ms | 8124 KB |
test_21.txt | TLE | 2211 ms | 8104 KB |
test_22.txt | TLE | 2207 ms | 8124 KB |
test_23.txt | TLE | 2207 ms | 8104 KB |
test_24.txt | TLE | 2207 ms | 8188 KB |
test_25.txt | TLE | 2207 ms | 8036 KB |
test_26.txt | TLE | 2207 ms | 8108 KB |
test_27.txt | TLE | 2208 ms | 8160 KB |
test_28.txt | TLE | 2208 ms | 8036 KB |
test_29.txt | TLE | 2208 ms | 8268 KB |
test_30.txt | TLE | 2208 ms | 8280 KB |
test_31.txt | TLE | 2208 ms | 8188 KB |
test_32.txt | TLE | 2211 ms | 8116 KB |
test_33.txt | TLE | 2208 ms | 8124 KB |
test_34.txt | TLE | 2208 ms | 8204 KB |
test_35.txt | TLE | 2208 ms | 8204 KB |
test_36.txt | TLE | 2211 ms | 8272 KB |
test_37.txt | TLE | 2208 ms | 8016 KB |
test_38.txt | TLE | 2208 ms | 8120 KB |
test_39.txt | TLE | 2208 ms | 8040 KB |