# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
849509 | 2023-09-14T20:00:43 Z | mickey080929 | Solitaire (JOI16_solitaire) | C++17 | 85 ms | 150876 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; ll modpow(ll a, ll b) { ll ret = 1; while (b > 0) { if (b & 1) ret = ret * a % mod; a = a * a % mod; b >>= 1; } return ret; } ll C(ll a, ll b) { if (b == 0) return 1; if (b == 1) return a; return a * (a+1) % mod; } ll n; char a[2010][3]; ll dp1[2010][6010]; ll dp2[2010][6010]; ll fac[6010]; int main() { fac[0] = 1; for (ll i=1; i<=6000; i++) fac[i] = fac[i-1] * i % mod; scanf("%lld", &n); ll cnt = 0; for (ll j=0; j<3; j++) { for (ll i=1; i<=n; i++) { scanf(" %c", &a[i][j]); if (a[i][j] == 'x') cnt ++; } } if (a[1][0] == 'x' || a[1][2] == 'x' || a[n][0] == 'x' || a[n][2] == 'x') { printf("0"); return 0; } for (ll i=1; i<=n-1; i++) { if (a[i][0] == 'x' && a[i+1][0] == 'x') { printf("0"); return 0; } if (a[i][2] == 'x' && a[i+1][2] == 'x') { printf("0"); return 0; } } ll ans = fac[cnt]; ll p = 0; for (ll i=1; i<=n; i++) { if (a[i][1] == 'o') { if (p == 0) continue; ll sum = 0; for (ll j=1; j<=p; j++) { sum += dp1[i-1][j] + dp2[i-1][j]; sum %= mod; } ans = ans * modpow(fac[p], mod-2) % mod * sum % mod; p = 0; continue; } ll t = (a[i][0] == 'x') + (a[i][2] == 'x'); if (p > 0) { ll sum = 0; for (ll j=1; j<=p; j++) sum = (sum + dp1[i-1][j]) % mod; for (ll j=1; j<=p+1; j++) { dp1[i][j+t] = sum * C(j, t) % mod; } sum = 0; for (ll j=p; j>=1; j--) { sum += dp2[i-1][j]; sum %= mod; dp1[i][j+t] = (dp1[i][j+t] + sum * C(j, t)) % mod; } sum = 0; for (ll j=2; j<=p+1; j++) { sum += dp1[i-1][j-1]; sum %= mod; for (ll k=0; k<=t-1; k++) { dp2[i][j+k] += sum * C(j, k) % mod * C(p-j+2, t-k) % mod * C(t, k); dp2[i][j+k] %= mod; } } } else { dp1[i][t+1] = fac[t]; if (i != 1) { if (t >= 1) dp2[i][1] = fac[t]; if (t == 2) dp2[i][2] = 2; } } p += t + 1; } if (p != 0) { ll sum = 0; for (ll j=1; j<=p; j++) { sum += dp1[n][j]; sum %= mod; } ans = ans * modpow(fac[p], mod-2) % mod * sum % mod; } printf("%lld", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 4856 KB | Output is correct |
3 | Correct | 1 ms | 2392 KB | Output is correct |
4 | Correct | 1 ms | 4440 KB | Output is correct |
5 | Correct | 1 ms | 4440 KB | Output is correct |
6 | Correct | 1 ms | 2392 KB | Output is correct |
7 | Correct | 1 ms | 4440 KB | Output is correct |
8 | Correct | 1 ms | 2392 KB | Output is correct |
9 | Correct | 1 ms | 2392 KB | Output is correct |
10 | Correct | 1 ms | 2396 KB | Output is correct |
11 | Correct | 1 ms | 4444 KB | Output is correct |
12 | Correct | 1 ms | 2392 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 60504 KB | Output is correct |
2 | Correct | 15 ms | 134748 KB | Output is correct |
3 | Correct | 6 ms | 52060 KB | Output is correct |
4 | Correct | 13 ms | 118872 KB | Output is correct |
5 | Correct | 14 ms | 139096 KB | Output is correct |
6 | Correct | 16 ms | 141144 KB | Output is correct |
7 | Correct | 17 ms | 144728 KB | Output is correct |
8 | Correct | 14 ms | 127064 KB | Output is correct |
9 | Correct | 14 ms | 130904 KB | Output is correct |
10 | Correct | 14 ms | 146776 KB | Output is correct |
11 | Correct | 15 ms | 150876 KB | Output is correct |
12 | Correct | 14 ms | 127064 KB | Output is correct |
13 | Correct | 12 ms | 94952 KB | Output is correct |
14 | Correct | 14 ms | 95064 KB | Output is correct |
15 | Correct | 14 ms | 95068 KB | Output is correct |
16 | Correct | 12 ms | 94976 KB | Output is correct |
17 | Correct | 15 ms | 95064 KB | Output is correct |
18 | Correct | 13 ms | 95064 KB | Output is correct |
19 | Correct | 14 ms | 97116 KB | Output is correct |
20 | Correct | 15 ms | 95064 KB | Output is correct |
21 | Correct | 15 ms | 95064 KB | Output is correct |
22 | Correct | 15 ms | 95068 KB | Output is correct |
23 | Correct | 14 ms | 95064 KB | Output is correct |
24 | Correct | 15 ms | 97112 KB | Output is correct |
25 | Correct | 16 ms | 97104 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4440 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 4440 KB | Output is correct |
4 | Correct | 1 ms | 4440 KB | Output is correct |
5 | Correct | 1 ms | 4440 KB | Output is correct |
6 | Correct | 1 ms | 2392 KB | Output is correct |
7 | Correct | 1 ms | 4440 KB | Output is correct |
8 | Correct | 1 ms | 4440 KB | Output is correct |
9 | Correct | 1 ms | 4440 KB | Output is correct |
10 | Correct | 1 ms | 4440 KB | Output is correct |
11 | Correct | 1 ms | 2392 KB | Output is correct |
12 | Correct | 1 ms | 4440 KB | Output is correct |
13 | Correct | 1 ms | 2392 KB | Output is correct |
14 | Correct | 1 ms | 2648 KB | Output is correct |
15 | Correct | 1 ms | 2392 KB | Output is correct |
16 | Correct | 1 ms | 2392 KB | Output is correct |
17 | Correct | 1 ms | 2392 KB | Output is correct |
18 | Correct | 1 ms | 2392 KB | Output is correct |
19 | Correct | 1 ms | 2392 KB | Output is correct |
20 | Correct | 1 ms | 2392 KB | Output is correct |
21 | Correct | 1 ms | 2392 KB | Output is correct |
22 | Correct | 1 ms | 2396 KB | Output is correct |
23 | Correct | 1 ms | 2392 KB | Output is correct |
24 | Correct | 1 ms | 2392 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 4856 KB | Output is correct |
3 | Correct | 1 ms | 2392 KB | Output is correct |
4 | Correct | 1 ms | 4440 KB | Output is correct |
5 | Correct | 1 ms | 4440 KB | Output is correct |
6 | Correct | 1 ms | 2392 KB | Output is correct |
7 | Correct | 1 ms | 4440 KB | Output is correct |
8 | Correct | 1 ms | 2392 KB | Output is correct |
9 | Correct | 1 ms | 2392 KB | Output is correct |
10 | Correct | 1 ms | 2396 KB | Output is correct |
11 | Correct | 1 ms | 4444 KB | Output is correct |
12 | Correct | 1 ms | 2392 KB | Output is correct |
13 | Correct | 2 ms | 4440 KB | Output is correct |
14 | Correct | 1 ms | 2396 KB | Output is correct |
15 | Correct | 1 ms | 4440 KB | Output is correct |
16 | Correct | 1 ms | 4440 KB | Output is correct |
17 | Correct | 1 ms | 4440 KB | Output is correct |
18 | Correct | 1 ms | 2392 KB | Output is correct |
19 | Correct | 1 ms | 4440 KB | Output is correct |
20 | Correct | 1 ms | 4440 KB | Output is correct |
21 | Correct | 1 ms | 4440 KB | Output is correct |
22 | Correct | 1 ms | 4440 KB | Output is correct |
23 | Correct | 1 ms | 2392 KB | Output is correct |
24 | Correct | 1 ms | 4440 KB | Output is correct |
25 | Correct | 1 ms | 2392 KB | Output is correct |
26 | Correct | 1 ms | 2648 KB | Output is correct |
27 | Correct | 1 ms | 2392 KB | Output is correct |
28 | Correct | 1 ms | 2392 KB | Output is correct |
29 | Correct | 1 ms | 2392 KB | Output is correct |
30 | Correct | 1 ms | 2392 KB | Output is correct |
31 | Correct | 1 ms | 2392 KB | Output is correct |
32 | Correct | 1 ms | 2392 KB | Output is correct |
33 | Correct | 1 ms | 2392 KB | Output is correct |
34 | Correct | 1 ms | 2396 KB | Output is correct |
35 | Correct | 1 ms | 2392 KB | Output is correct |
36 | Correct | 1 ms | 2392 KB | Output is correct |
37 | Correct | 1 ms | 8536 KB | Output is correct |
38 | Correct | 2 ms | 12632 KB | Output is correct |
39 | Correct | 1 ms | 6492 KB | Output is correct |
40 | Correct | 2 ms | 19288 KB | Output is correct |
41 | Correct | 3 ms | 23128 KB | Output is correct |
42 | Correct | 3 ms | 21080 KB | Output is correct |
43 | Correct | 3 ms | 25176 KB | Output is correct |
44 | Correct | 2 ms | 19032 KB | Output is correct |
45 | Correct | 3 ms | 25176 KB | Output is correct |
46 | Correct | 3 ms | 19032 KB | Output is correct |
47 | Correct | 3 ms | 25176 KB | Output is correct |
48 | Correct | 2 ms | 17244 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 4856 KB | Output is correct |
3 | Correct | 1 ms | 2392 KB | Output is correct |
4 | Correct | 1 ms | 4440 KB | Output is correct |
5 | Correct | 1 ms | 4440 KB | Output is correct |
6 | Correct | 1 ms | 2392 KB | Output is correct |
7 | Correct | 1 ms | 4440 KB | Output is correct |
8 | Correct | 1 ms | 2392 KB | Output is correct |
9 | Correct | 1 ms | 2392 KB | Output is correct |
10 | Correct | 1 ms | 2396 KB | Output is correct |
11 | Correct | 1 ms | 4444 KB | Output is correct |
12 | Correct | 1 ms | 2392 KB | Output is correct |
13 | Correct | 8 ms | 60504 KB | Output is correct |
14 | Correct | 15 ms | 134748 KB | Output is correct |
15 | Correct | 6 ms | 52060 KB | Output is correct |
16 | Correct | 13 ms | 118872 KB | Output is correct |
17 | Correct | 14 ms | 139096 KB | Output is correct |
18 | Correct | 16 ms | 141144 KB | Output is correct |
19 | Correct | 17 ms | 144728 KB | Output is correct |
20 | Correct | 14 ms | 127064 KB | Output is correct |
21 | Correct | 14 ms | 130904 KB | Output is correct |
22 | Correct | 14 ms | 146776 KB | Output is correct |
23 | Correct | 15 ms | 150876 KB | Output is correct |
24 | Correct | 14 ms | 127064 KB | Output is correct |
25 | Correct | 12 ms | 94952 KB | Output is correct |
26 | Correct | 14 ms | 95064 KB | Output is correct |
27 | Correct | 14 ms | 95068 KB | Output is correct |
28 | Correct | 12 ms | 94976 KB | Output is correct |
29 | Correct | 15 ms | 95064 KB | Output is correct |
30 | Correct | 13 ms | 95064 KB | Output is correct |
31 | Correct | 14 ms | 97116 KB | Output is correct |
32 | Correct | 15 ms | 95064 KB | Output is correct |
33 | Correct | 15 ms | 95064 KB | Output is correct |
34 | Correct | 15 ms | 95068 KB | Output is correct |
35 | Correct | 14 ms | 95064 KB | Output is correct |
36 | Correct | 15 ms | 97112 KB | Output is correct |
37 | Correct | 16 ms | 97104 KB | Output is correct |
38 | Correct | 2 ms | 4440 KB | Output is correct |
39 | Correct | 1 ms | 2396 KB | Output is correct |
40 | Correct | 1 ms | 4440 KB | Output is correct |
41 | Correct | 1 ms | 4440 KB | Output is correct |
42 | Correct | 1 ms | 4440 KB | Output is correct |
43 | Correct | 1 ms | 2392 KB | Output is correct |
44 | Correct | 1 ms | 4440 KB | Output is correct |
45 | Correct | 1 ms | 4440 KB | Output is correct |
46 | Correct | 1 ms | 4440 KB | Output is correct |
47 | Correct | 1 ms | 4440 KB | Output is correct |
48 | Correct | 1 ms | 2392 KB | Output is correct |
49 | Correct | 1 ms | 4440 KB | Output is correct |
50 | Correct | 1 ms | 2392 KB | Output is correct |
51 | Correct | 1 ms | 2648 KB | Output is correct |
52 | Correct | 1 ms | 2392 KB | Output is correct |
53 | Correct | 1 ms | 2392 KB | Output is correct |
54 | Correct | 1 ms | 2392 KB | Output is correct |
55 | Correct | 1 ms | 2392 KB | Output is correct |
56 | Correct | 1 ms | 2392 KB | Output is correct |
57 | Correct | 1 ms | 2392 KB | Output is correct |
58 | Correct | 1 ms | 2392 KB | Output is correct |
59 | Correct | 1 ms | 2396 KB | Output is correct |
60 | Correct | 1 ms | 2392 KB | Output is correct |
61 | Correct | 1 ms | 2392 KB | Output is correct |
62 | Correct | 1 ms | 8536 KB | Output is correct |
63 | Correct | 2 ms | 12632 KB | Output is correct |
64 | Correct | 1 ms | 6492 KB | Output is correct |
65 | Correct | 2 ms | 19288 KB | Output is correct |
66 | Correct | 3 ms | 23128 KB | Output is correct |
67 | Correct | 3 ms | 21080 KB | Output is correct |
68 | Correct | 3 ms | 25176 KB | Output is correct |
69 | Correct | 2 ms | 19032 KB | Output is correct |
70 | Correct | 3 ms | 25176 KB | Output is correct |
71 | Correct | 3 ms | 19032 KB | Output is correct |
72 | Correct | 3 ms | 25176 KB | Output is correct |
73 | Correct | 2 ms | 17244 KB | Output is correct |
74 | Correct | 11 ms | 98392 KB | Output is correct |
75 | Correct | 5 ms | 44576 KB | Output is correct |
76 | Correct | 8 ms | 69208 KB | Output is correct |
77 | Correct | 14 ms | 129880 KB | Output is correct |
78 | Correct | 14 ms | 133720 KB | Output is correct |
79 | Correct | 14 ms | 138840 KB | Output is correct |
80 | Correct | 15 ms | 137560 KB | Output is correct |
81 | Correct | 15 ms | 133200 KB | Output is correct |
82 | Correct | 13 ms | 117848 KB | Output is correct |
83 | Correct | 14 ms | 134740 KB | Output is correct |
84 | Correct | 15 ms | 126552 KB | Output is correct |
85 | Correct | 14 ms | 125532 KB | Output is correct |
86 | Correct | 76 ms | 113636 KB | Output is correct |
87 | Correct | 77 ms | 113492 KB | Output is correct |
88 | Correct | 76 ms | 113232 KB | Output is correct |
89 | Correct | 77 ms | 113744 KB | Output is correct |
90 | Correct | 76 ms | 113488 KB | Output is correct |
91 | Correct | 77 ms | 114000 KB | Output is correct |
92 | Correct | 85 ms | 113744 KB | Output is correct |
93 | Correct | 76 ms | 113744 KB | Output is correct |
94 | Correct | 77 ms | 113612 KB | Output is correct |
95 | Correct | 77 ms | 114004 KB | Output is correct |
96 | Correct | 77 ms | 113804 KB | Output is correct |
97 | Correct | 77 ms | 113316 KB | Output is correct |