답안 #728842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728842 2023-04-23T07:38:14 Z abcvuitunggio Solitaire (JOI16_solitaire) C++17
0 / 100
3 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){
    if (check(i-1,j,mask)&&check(i+1,j,mask))
        return true;
    if (check(i,j-1,mask)&&check(i,j+1,mask))
        return true;
    return false;
}
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)));
    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:25: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]
   25 |     for (int i=0;i<v.size();i++)
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Incorrect 3 ms 596 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Incorrect 3 ms 596 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Incorrect 3 ms 596 KB Output isn't correct
3 Halted 0 ms 0 KB -