Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define mk make_pair
- #define fi first
- #define se second
- #define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
- using namespace std;
- typedef vector<int> vi;
- typedef pair<int,int> ii;
- typedef long long ll;
- typedef vector<bool> vb;
- const int N=1010;
- ll sm, s, n, r[N], c[N], m[N][N], a[N][N];
- int main(void) {
- cin >> n;
- For(i,0,n)
- For(j,0,n) {
- cin >> m[i][j];
- c[j]+=m[i][j];
- r[i]+=m[i][j];
- sm += m[i][j];
- }
- if (n == 1) {
- if (m[0][0] == 0 || m[0][0] == 1)
- goto ans_1;
- goto ans_0;
- }
- if (sm % (2*n - 1) != 0)
- goto ans_0;
- s = sm / (ll)(2*n-1);
- for (int i = 0; i<n; i++)
- for (int j = 0; j<n; j++) {
- if ((c[j]-s)%(n-1) != 0)
- goto ans_0;
- ll sa = (c[j]-s)/(n-1);
- if ((r[i]-s)%(n-1) != 0)
- goto ans_0;
- ll sb = (r[i]-s)/(n-1);
- a[i][j] = sa + sb - m[i][j];
- if (a[i][j] > 1 || a[i][j] < 0)
- goto ans_0;
- }
- ans_1:
- cout << "1\n";
- return 0;
- ans_0:
- cout << "0\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement