#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}; std::chrono::system_clock::time_point start; start = std::chrono::system_clock::now(); double elapsed; lli ansScore = INF; bool check = false; while(1){ if(check || cnt%1000==0){ std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); elapsed = std::chrono::duration_cast(now-start).count(); if(elapsed > 1700*1000){ check = true; } if(elapsed > 1900*1000){ break; } } 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){ LOG3(cnt,nowScore,nexScore); REP(i,0,N){ REP(j,0,N){ cout<>t; while(t--)solve(); return 0; }