Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int F[250001];
- int main()
- {
- int n;
- cin>>n;
- int a[n][n],np=n*n;;
- unsigned long long int s,s_ant;
- for(int i=0;i<n;++i)
- {
- s=0;
- for(int j=0;j<n;++j)
- {
- cin>>a[i][j];
- if(a[i][j]<1||a[i][j]>np)
- {
- cout<<"false";
- return 0;
- }
- ++F[a[i][j]],s+=a[i][j];
- }
- if(i&&s!=s_ant)
- {
- cout<<"false";
- return 0;
- }
- s_ant=s;
- }
- for(int i=1;i<=np;++i)
- if(F[i]>1)
- {
- cout<<"false";
- return 0;
- }
- for(int j=0;j<n;++j)
- {
- s=0;
- for(int i=0;i<n;++i)
- s+=a[i][j];
- if(j&&s!=s_ant)
- {
- cout<<"false";
- return 0;
- }
- s_ant=s;
- }
- s=0;
- for(int i=0;i<n;++i)
- s+=a[i][i];
- if(s!=s_ant)
- {
- cout<<"false";
- return 0;
- }
- s=0;
- for(int i=0;i<n;++i)
- s+=a[n-i-1][i];
- if(s!=s_ant)
- {
- cout<<"false";
- return 0;
- }
- cout<<"true";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement