This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bitset>
using namespace std;
char g[10][10];
int n,m;
int ind(int i,int j)
{
return (i*(m-1))+j;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int k;
cin>>n>>m>>k;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
g[i][j]='?';
for(int j=0;j<k;j++)
{
char c;
cin>>c;
int x,y;
cin>>x>>y;
x--;y--;
g[x][y]=c;
}
int ans=0;
int lt=n*m;
int pw=(1<<lt);
for(int mask=0;mask<pw;mask++)
{
bool pos=1;
// (i,j) = (i*m)+j
// cout<<"Grid "<<mask<<endl;
for(int i=0;pos and i<n;i++)
{
for(int j=0;j<m;j++)
{
char f=(((mask&(1<<ind(i,j)))>0)?'+':'-');
// cout<<f<<' ';
if(f!=g[i][j] and g[i][j]!='?')
{
pos=0;
break;
}
}
// cout<<endl;
}
// cout<<"endl"<<endl;
if(!pos)
continue;
for(int i=1;i<n and pos;i++)
{
for(int j=1;j<m;j++)
{
int f=(((mask&(1<<ind(i-1,j-1)))>0)?1:-1);
int s=(((mask&(1<<ind(i-1,j)))>0)?1:-1);
int f1=(((mask&(1<<ind(i,j-1)))>0)?1:-1);
int s1=(((mask&(1<<ind(i,j)))>0)?1:-1);
if((f+s+f1+s1)!=0)
{
pos=0;
break;
}
}
}
if(!pos)
continue;
// cout<<"Grid "<<mask<<endl;
// for(int i=0;pos and i<n;i++)
// {
// for(int j=0;j<m;j++)
// {
// char f=(((mask&(1<<ind(i,j)))>0)?'+':'-');
// cout<<f<<' ';
// }
// cout<<endl;
// }
// cout<<"endl"<<endl;
ans++;
}
cout<<ans<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |