Submission #729186

# Submission time Handle Problem Language Result Execution time Memory
729186 2023-04-23T15:24:28 Z abcvuitunggio None (JOI16_solitaire) C++17
100 / 100
103 ms 77388 KB
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int n,cnt,f[6001],f2[6001],dp[2001][6001][2],pre[2001][6001],suf[2001][6002];
string s[3];
pair <int, int> p;
vector <int> v;
int pw(int a, int b){
    if (!b)
        return 1;
    int t=pw(a,b>>1);
    t=(1LL*t*t)%mod;
    return (b&1?(1LL*t*a)%mod:t);
}
int C(int n, int k){
    return 1LL*f[n]*f2[k]%mod*f2[n-k]%mod;
}
void solve(){
    if (v.empty())
        return;
    int cnt=0;
    for (int i=0;i<v.size();i++){
        cnt+=v[i]+1;
        for (int j=1;j<=cnt+1;j++){
            dp[i][j][0]=dp[i][j][1]=pre[i][j]=suf[i][j]=0;
            if (!i){
                if (!v[i])
                    dp[i][j][0]=dp[i][j][1]=1;
                else if (v[i]==1){
                    dp[i][j][0]=j-1;
                    dp[i][j][1]=1;
                }
                else if (v[i]==2){
                    dp[i][j][0]=(j==3)*2;
                    dp[i][j][1]=2;
                }
                continue;
            }
            if (!v[i]){
                dp[i][j][0]=dp[i][j][1]=(pre[i-1][j-1]+suf[i-1][j])%mod;
                continue;
            }
            if (v[i]==1){
                dp[i][j][0]=1LL*((j>1?pre[i-1][j-2]:0)+suf[i-1][max(j-1,1)])%mod*(j-1)%mod;
                dp[i][j][1]=(dp[i][j][0]+1LL*pre[i-1][j-1]*(cnt-j)%mod)%mod;
                continue;
            }
            dp[i][j][0]=1LL*((j>2?pre[i-1][j-3]:0)+suf[i-1][max(j-2,1)])%mod*(j-1)%mod*(j-2)%mod;
            dp[i][j][1]=((dp[i][j][0]+1LL*pre[i-1][j-1]*(cnt-j)%mod*(cnt-j-1)%mod)%mod+1LL*pre[i-1][j-2]*(cnt-j)%mod*(j-1)*2%mod)%mod;
        }
        for (int j=1;j<=cnt;j++)
            pre[i][j]=(pre[i][j-1]+dp[i][j][0])%mod;
        for (int j=cnt;j;j--)
            suf[i][j]=(suf[i][j+1]+dp[i][j][1])%mod;
    }
    p.second+=cnt;
    p.first=1LL*p.first*suf[v.size()-1][1]%mod*C(p.second,p.second-cnt)%mod;
    v.clear();
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    f[0]=f2[0]=1;
    for (int i=1;i<=6000;i++){
        f[i]=1LL*f[i-1]*i%mod;
        f2[i]=pw(f[i],mod-2);
    }
    cin >> n >> s[0] >> s[1] >> s[2];
    s[1]+='o';
    if (s[0][0]=='x'||s[0][n-1]=='x'||s[2][0]=='x'||s[2][n-1]=='x'){
        cout << 0;
        return 0;
    }
    for (int i=0;i<n-1;i++)
        if ((s[0][i]=='x'&&s[0][i+1]=='x')||(s[2][i]=='x'&&s[2][i+1]=='x')){
            cout << 0;
            return 0;
        }
    for (int i=0;i<n;i++){
        cnt+=(s[0][i]=='x'&&s[1][i]=='o');
        cnt+=(s[2][i]=='x'&&s[1][i]=='o');
    }
    p={f[cnt],cnt};
    for (int i=0;i<=n;i++){
        if (s[1][i]=='o'){
            solve();
            continue;
        }
        v.push_back((s[0][i]=='x')+(s[2][i]=='x'));
    }
    cout << p.first;
}

Compilation message

solitaire.cpp: In function 'void solve()':
solitaire.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i=0;i<v.size();i++){
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 7 ms 5076 KB Output is correct
14 Correct 9 ms 6612 KB Output is correct
15 Correct 11 ms 11824 KB Output is correct
16 Correct 7 ms 6228 KB Output is correct
17 Correct 11 ms 9556 KB Output is correct
18 Correct 10 ms 7584 KB Output is correct
19 Correct 11 ms 10324 KB Output is correct
20 Correct 11 ms 11284 KB Output is correct
21 Correct 11 ms 9812 KB Output is correct
22 Correct 13 ms 12644 KB Output is correct
23 Correct 11 ms 8412 KB Output is correct
24 Correct 12 ms 9800 KB Output is correct
25 Correct 11 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 2 ms 724 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 2 ms 724 KB Output is correct
34 Correct 2 ms 724 KB Output is correct
35 Correct 2 ms 724 KB Output is correct
36 Correct 2 ms 724 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 3 ms 340 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 372 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 2 ms 492 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 7 ms 5076 KB Output is correct
26 Correct 9 ms 6612 KB Output is correct
27 Correct 11 ms 11824 KB Output is correct
28 Correct 7 ms 6228 KB Output is correct
29 Correct 11 ms 9556 KB Output is correct
30 Correct 10 ms 7584 KB Output is correct
31 Correct 11 ms 10324 KB Output is correct
32 Correct 11 ms 11284 KB Output is correct
33 Correct 11 ms 9812 KB Output is correct
34 Correct 13 ms 12644 KB Output is correct
35 Correct 11 ms 8412 KB Output is correct
36 Correct 12 ms 9800 KB Output is correct
37 Correct 11 ms 9684 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 724 KB Output is correct
51 Correct 2 ms 724 KB Output is correct
52 Correct 2 ms 724 KB Output is correct
53 Correct 2 ms 724 KB Output is correct
54 Correct 2 ms 724 KB Output is correct
55 Correct 2 ms 724 KB Output is correct
56 Correct 3 ms 724 KB Output is correct
57 Correct 2 ms 724 KB Output is correct
58 Correct 2 ms 724 KB Output is correct
59 Correct 2 ms 724 KB Output is correct
60 Correct 2 ms 724 KB Output is correct
61 Correct 2 ms 724 KB Output is correct
62 Correct 2 ms 340 KB Output is correct
63 Correct 2 ms 340 KB Output is correct
64 Correct 3 ms 340 KB Output is correct
65 Correct 2 ms 468 KB Output is correct
66 Correct 2 ms 340 KB Output is correct
67 Correct 2 ms 372 KB Output is correct
68 Correct 2 ms 468 KB Output is correct
69 Correct 2 ms 384 KB Output is correct
70 Correct 2 ms 512 KB Output is correct
71 Correct 2 ms 468 KB Output is correct
72 Correct 2 ms 492 KB Output is correct
73 Correct 2 ms 468 KB Output is correct
74 Correct 2 ms 468 KB Output is correct
75 Correct 3 ms 596 KB Output is correct
76 Correct 2 ms 468 KB Output is correct
77 Correct 3 ms 468 KB Output is correct
78 Correct 2 ms 596 KB Output is correct
79 Correct 2 ms 468 KB Output is correct
80 Correct 2 ms 508 KB Output is correct
81 Correct 3 ms 468 KB Output is correct
82 Correct 2 ms 596 KB Output is correct
83 Correct 2 ms 468 KB Output is correct
84 Correct 2 ms 468 KB Output is correct
85 Correct 2 ms 468 KB Output is correct
86 Correct 96 ms 77120 KB Output is correct
87 Correct 97 ms 76948 KB Output is correct
88 Correct 97 ms 76380 KB Output is correct
89 Correct 103 ms 76788 KB Output is correct
90 Correct 101 ms 76364 KB Output is correct
91 Correct 101 ms 77388 KB Output is correct
92 Correct 99 ms 77120 KB Output is correct
93 Correct 97 ms 76772 KB Output is correct
94 Correct 95 ms 77092 KB Output is correct
95 Correct 98 ms 76696 KB Output is correct
96 Correct 96 ms 76652 KB Output is correct
97 Correct 98 ms 76336 KB Output is correct