Submission #728851

# Submission time Handle Problem Language Result Execution time Memory
728851 2023-04-23T07:45:17 Z abcvuitunggio None (JOI16_solitaire) C++17
10 / 100
10 ms 980 KB
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int n,dp[1<<16],a[3][2000];
string s[3];
vector <pair <int, int>> v;
bool check(int i, int j, int mask){
    if (i<0||i>2||j<0||j>=n)
        return false;
    return (s[i][j]=='o'||((mask>>a[i][j])&1));
}
bool check2(int i, int j, int mask){
    return ((check(i-1,j,mask)&&check(i+1,j,mask))||(check(i,j-1,mask)&&check(i,j+1,mask)));
}
int f(int mask){
    if (mask==(1<<v.size())-1)
        return 1;
    if (dp[mask]!=-1)
        return dp[mask];
    dp[mask]=0;
    for (int i=0;i<v.size();i++)
        if (!((mask>>i)&1))
            if (check2(v[i].first,v[i].second,mask))
                dp[mask]=(dp[mask]+f(mask|(1<<i)))%mod;
    return dp[mask];
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> s[0] >> s[1] >> s[2];
    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<3;i++)
        for (int j=0;j<n;j++)
            if (s[i][j]=='x'){
                a[i][j]=v.size();
                v.push_back({i,j});
            }
    memset(dp,-1,sizeof(dp));
    cout << f(0);
}

Compilation message

solitaire.cpp: In function 'int f(int)':
solitaire.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i=0;i<v.size();i++)
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 1 ms 584 KB Output is correct
4 Correct 7 ms 600 KB Output is correct
5 Correct 10 ms 592 KB Output is correct
6 Correct 5 ms 596 KB Output is correct
7 Correct 4 ms 584 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 5 ms 468 KB Output is correct
11 Correct 4 ms 584 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 1 ms 584 KB Output is correct
4 Correct 7 ms 600 KB Output is correct
5 Correct 10 ms 592 KB Output is correct
6 Correct 5 ms 596 KB Output is correct
7 Correct 4 ms 584 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 5 ms 468 KB Output is correct
11 Correct 4 ms 584 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Runtime error 1 ms 980 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 1 ms 584 KB Output is correct
4 Correct 7 ms 600 KB Output is correct
5 Correct 10 ms 592 KB Output is correct
6 Correct 5 ms 596 KB Output is correct
7 Correct 4 ms 584 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 5 ms 468 KB Output is correct
11 Correct 4 ms 584 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Runtime error 1 ms 980 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -