You’re given a matrix A of size n × n.
Let’s call the matrix with nonnegative elements magic if it is symmetric (so ai,j = aj,i ), ai,i = 0 and ai,j ≤ max(ai,k, aj,k) for all triples i, j, k. Note that i, j, k do not need to be distinct.
Determine if the matrix is magic.
论bitset的重要性
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define pi acos(-1)
#define inf (1<<30)
#define INF (1<<62)
#define fi first
#define se second
#define CLR(x,f) memset(x,f,sizeof(x))
#define CPY(x,y) memcpy(x,y,sizeof(x))
#define prt(x) cout<<#x<<": "<
#define Har(x) printf("--------DEBUG(%d)--------\n",x)
//#define TL
using namespace std;
const int M=2500;
bitset b[M];
typedef long long ll;
int a[M][M],n;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
iii dat[M*M];
bool judge(){
for(int i=0;iif (a[i][i])return 0;
for(int i=0;ifor(int j=0;jif(a[i][j]-a[j][i])return 0;
int tot=0;
for(int i=0;ifor(int j=0;jfor(int j,i=0;ifor(j=i;jfor(int k=i;kif((b[v.fi]&b[v.se]).any())return false;
}
for(int k=i;ktrue;
}
i=j-1;
}
return true;
}
int main(){
#ifdef TL
#endif
scanf("%d",&n);
for(int i=0;ifor(int j=0;jscanf("%d",&a[i][j]);
if(judge())puts("MAGIC");
else puts("NOT MAGIC");
return 0;
}