제출 #1166565

#제출 시각아이디문제언어결과실행 시간메모리
1166565ByeWorldChessboard (IZhO18_chessboard)C++20
100 / 100
569 ms4348 KiB
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<pii,int> ipii;
typedef pair<pii,pii> ipiii;
const int MAXN = 2e5+10;
const int MAXA = 1e7+10;
const int INF = 1e18+10;
const int SQRT = 300;
const int LOG = 20;
const ld EPS = 1e-6;
const int MOD = 998244353;
int sum(int a, int b){ return (a+b)%MOD; }
void chsum(int &a, int b){ a = (a+b)%MOD; }
void chsub(int &a, int b){ a = (a+MOD-b)%MOD; }
int mul(int a, int b){ return (a*b)%MOD; }
void chmul(int &a, int b){ a = (a*b)%MOD; }
void chmn(int &a, int b){ a = min(a, b); }
void chmx(int &a, int b){ a = max(a, b); }

int n, m, a[MAXN][5];
int ans = INF, siz;
int bl = 0, wh = 0;

void tot(int x, int y, int ty){
	if(x==-1 || y==-1) return;
	int r = x/siz, c = y/siz;
	if((r+c)%2 == 0) bl += ty * (x-r*siz) * (y-c*siz);
	else wh += ty * (x-r*siz) * (y-c*siz);

	int p = ty * (y-c*siz) * siz * ((r+1)/2), q = ty * (y-c*siz) * siz * (r/2);
	if(c%2 == 0) bl += p, wh += q;
	else bl += q, wh += p;

	p = ty * (x-r*siz) * siz * ((c+1)/2), q = ty * (x-r*siz) * siz * (c/2);
	if(r%2 == 0) bl += p, wh += q;
	else bl += q, wh += p;

	p = ty * siz * siz * ((r*c+1)/2), q = ty * siz * siz * ((r*c)/2);
	bl += p; wh += q;
}
void cnt(){
	bl = 0; wh = 0;
	for(int i=1; i<=m; i++){
		tot(a[i][3], a[i][4], 1);
		tot(a[i][1]-1, a[i][2]-1, 1);
		tot(a[i][3], a[i][2]-1, -1);
		tot(a[i][1]-1, a[i][4], -1);
	}
	// cout << siz << ' ' << bl << ' ' << wh << " wh\n";

	int blcell = ((n/siz)*(n/siz)+1)/2; blcell *= siz*siz;
	int whcell = (n/siz)*(n/siz)/2; whcell *= siz*siz;
	chmn(ans, blcell -bl+wh);
	chmn(ans, whcell -wh+bl);
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1; i<=m; i++){
    	cin>>a[i][1] >> a[i][2]>>a[i][3]>>a[i][4];
    }
    for(int ss=1; ss<n; ss++){
    	if(n%ss==0){
    		siz = ss;
    		cnt();
    	}
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...