This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;
int n, m, k, x[5][5];
vector<int> v;
void solve(){
cin >> n >> m >> k;
for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) x[i][j] = -1;
for(int i = 0; i < k; ++i){
char c; int a, b; cin >> c >> a >> b;
a--, b--;
if(c=='+') x[a][b] = 1;
else x[a][b] = 0;
}
for(int mask = 0; mask < (1<<n); ++mask){
bool o = 1;
for(int i = 0; i < n; ++i){
if(x[i][0] != -1){
if(((mask&(1<<i)) > 0) != x[i][0]){
o = 0;
break;
}
}
}
if(o) v.pb(mask);
}
for(int j = 1; j < m; ++j){
vector<int> t;
for(int mask = 0; mask < (1<<n); ++mask){
bool o = 1;
for(int i = 0; i < n; ++i){
if(x[i][j] != -1){
if(((mask&(1<<i)) > 0) != x[i][j]){
o = 0;
break;
}
}
}
if(!o) continue;
for(int k: v){
bool ok = 1;
for(int i = 1; i < n; ++i){
int x = (mask&(1<<(i-1)))>0;
int y = (k&(1<<i))>0;
int z = (k&(1<<(i-1)))>0;
int w = (mask&(1<<i))>0;
if(x+y+z+w != 2){
ok = 0;
break;
}
}
if(ok){
t.pb(mask);
}
}
}
v = t;
}
cout << v.size();
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
cout << '\n';
}
return 0;
}
Compilation message (stderr)
plusminus.cpp: In function 'int main()':
plusminus.cpp:83:16: warning: unused variable 'aa' [-Wunused-variable]
83 | int T = 1, aa;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |