Submission #728851

#TimeUsernameProblemLanguageResultExecution timeMemory
728851abcvuitunggioSolitaire (JOI16_solitaire)C++17
10 / 100
10 ms980 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...