Submission #729184

# Submission time Handle Problem Language Result Execution time Memory
729184 2023-04-23T15:22:34 Z abcvuitunggio None (JOI16_solitaire) C++17
42 / 100
15 ms 12756 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+1LL*pre[i-1][j-2]*(cnt-j)%mod*(j-1)*2%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 3 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 468 KB Output is correct
4 Correct 2 ms 508 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 468 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 384 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 5140 KB Output is correct
14 Correct 9 ms 6612 KB Output is correct
15 Correct 12 ms 11860 KB Output is correct
16 Correct 8 ms 6144 KB Output is correct
17 Correct 12 ms 9556 KB Output is correct
18 Correct 9 ms 7636 KB Output is correct
19 Correct 11 ms 10324 KB Output is correct
20 Correct 12 ms 11348 KB Output is correct
21 Correct 11 ms 9812 KB Output is correct
22 Correct 15 ms 12756 KB Output is correct
23 Correct 12 ms 8320 KB Output is correct
24 Correct 13 ms 9812 KB Output is correct
25 Correct 12 ms 9728 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 380 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 2 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 3 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 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 380 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 2 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 356 KB Output is correct
38 Correct 2 ms 380 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Incorrect 2 ms 504 KB Output isn't correct
41 Halted 0 ms 0 KB -
# 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 3 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 468 KB Output is correct
16 Correct 2 ms 508 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 468 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 384 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 5140 KB Output is correct
26 Correct 9 ms 6612 KB Output is correct
27 Correct 12 ms 11860 KB Output is correct
28 Correct 8 ms 6144 KB Output is correct
29 Correct 12 ms 9556 KB Output is correct
30 Correct 9 ms 7636 KB Output is correct
31 Correct 11 ms 10324 KB Output is correct
32 Correct 12 ms 11348 KB Output is correct
33 Correct 11 ms 9812 KB Output is correct
34 Correct 15 ms 12756 KB Output is correct
35 Correct 12 ms 8320 KB Output is correct
36 Correct 13 ms 9812 KB Output is correct
37 Correct 12 ms 9728 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 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 380 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 2 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 356 KB Output is correct
63 Correct 2 ms 380 KB Output is correct
64 Correct 2 ms 340 KB Output is correct
65 Incorrect 2 ms 504 KB Output isn't correct
66 Halted 0 ms 0 KB -