#include using namespace std; #define lli long long int #define REP(i,s,n) for(lli i=s;i rand(0, N-1); // [0, 99] 範囲の一様乱数 lli cnt = 0; lli id[2]={0,0}; lli jd[2]={0,0}; while(cnt < 1000000){ lli fromI = rand(mt); lli toI = rand(mt); lli fromJ = rand(mt); lli toJ = rand(mt); if(q[fromI][fromJ] <= 0 || q[toI][toJ] <= 0)continue; if(fromI == toI || fromJ == toJ) continue; id[0]=fromI,id[1]=toI; jd[0]=fromJ,jd[1]=toJ; //LOG4(fromI,toI,fromJ,toJ); lli nexScore = nowScore; REP(i,0,2)REP(j,0,2)nexScore -= pow2(p[id[i]][jd[j]]-q[id[i]][jd[j]]); //LOG(nexScore); q[fromI][fromJ]--; q[fromI][toJ]++; q[toI][toJ]--; q[toI][fromJ]++; REP(i,0,2)REP(j,0,2)nexScore += pow2(p[id[i]][jd[j]]-q[id[i]][jd[j]]); if(0){ LOG2(cnt,nexScore); REP(i,0,N){ REP(j,0,N){ cout< nowScore){ q[fromI][fromJ]++; q[fromI][toJ]--; q[toI][toJ]++; q[toI][fromJ]--; } else{ nowScore = nexScore; } cnt++; } cout<>t; while(t--)solve(); return 0; }