Skip to content

Instantly share code, notes, and snippets.

@algon-320
Last active July 1, 2017 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save algon-320/896968e8aa70096bf6ee57199ecb898d to your computer and use it in GitHub Desktop.
Save algon-320/896968e8aa70096bf6ee57199ecb898d to your computer and use it in GitHub Desktop.
NiceTable
#include <bits/stdc++.h>
using namespace std;
struct NiceTable {
string isNice(vector<string> t) {
int n=t.size();
int m=t[0].size();
for(int x=0; x<(1<<n); x++) {
for(int y=0; y<(1<<m); y++) {
bool ok=true;
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
int Y=!!(y&(1<<j));
int X=!!(x&(1<<i));
if((X^Y)!=t[i][j]-'0') ok=false;
}
}
if(ok) {
return "Nice";
}
}
}
return "Not nice";
}
};
#include <bits/stdc++.h>
using namespace std;
struct NiceTable {
string isNice(vector<string> t) {
int n=t.size();
int m=t[0].size();
vector<int> x,y;
if(t[0][0]=='0') x.push_back(1), y.push_back(1);
if(t[0][0]=='1') x.push_back(1), y.push_back(0);
for(int i=1; i<n; i++) {
x.push_back((t[i][0]-'0')^y[0]);
}
for(int i=1; i<m; i++) {
y.push_back((t[0][i]-'0')^x[0]);
}
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if((x[i]^y[j])!=t[i][j]-'0') return "Not nice";
}
}
return "Nice";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment