답안 #496970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496970 2021-12-22T07:48:39 Z Gurban Chessboard (IZhO18_chessboard) C++17
0 / 100
43 ms 8860 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int maxn=1e5+5;
int n,k;
int xl[maxn],yl[maxn];
int xr[maxn],yr[maxn];
vector<int>v[maxn],p[maxn];

bool col(int pos,int nw,int X){
	int now = (pos + X - 1) / X;
	now %= 2; now ^= 1;
	return now ^ nw;
}

ll f(int X,int tp){
	ll now = 0;
	int nw = tp ^ 1;
	for(int i = 1;i <= n;i++){
		if(X == 1 or i % X == 1) nw ^= 1;

		if(!(tp ^ nw)) now += 1ll * (n/X + 1)/2 * X;
		else now += 1ll * (n/X) / 2 * X;	
	}

	// if(X == 2 and tp == 1) cout<<now<<'\n';

	nw = tp;
	ll cnt[2]; cnt[0] = cnt[1] = 0;
	for(int i = 1;i <= n;i++){
		if(i % X == 1 or X == 1){
			nw ^= 1;
			swap(cnt[0],cnt[1]);
		}
		for(auto j : v[i]){
			int z = xl[j] + (X + 1 - (xl[j] % X));
			if(xl[j] % X == 0) z = xl[j] + 1;
			
			// if(X == 2 and tp == 1 and i == 3) cout<<xl[j]<<' '<<z<<'\n';

			if(xr[j] < z){
				int cln = col(xl[j],nw,X);
				cnt[cln] += (xr[j] - xl[j] + 1);
				
				continue;
			}
			if(xr[j] < z + X - 1){
				int cln = col(xl[j],nw,X);
				
				// if(X == 2 and tp == 1) cout<<cln<<' '<<nw<<'\n';

				cnt[cln] += (z - xl[j]);

				cln = col(xr[j],nw,X);
				
				cnt[cln] += (xr[j] - z + 1);
				
				continue;
			}

			int pos = xr[j] - (xr[j] % X) + 1;
			// if(X == 2 and tp == 1 and i == 3) cout<<xr[j]<<' '<<pos<<'\n';
			int cln = col(z,nw,X);
			
			cnt[cln] += ((pos - z) / X + 1)/2 * X;
			cnt[cln ^ 1] += ((pos-z)/X)/2 * X;
			
			cln = col(xl[j],nw,X);
			
			cnt[cln] += (z - xl[j]);

			cln = col(xr[j],nw,X);
			
			cnt[cln] += (xr[j] - pos + 1);
			
		}
		
		now += cnt[0];
		now -= cnt[1];

		// if(X == 2 and tp == 1) cout<<i<<' '<<cnt[0]<<' '<<cnt[1]<<'\n';

		for(auto j : p[i]){
			int z = xl[j] + (X + 1 - (xl[j] % X));
			if(xr[j] < z){
				int cln = col(xl[j],nw,X);
				cnt[cln] -= (xr[j] - xl[j] + 1);
				
				continue;
			}
			if(xr[j] < z + X - 1){
				int cln = col(xl[j],nw,X);
				
				cnt[cln] -= (z - xl[j]);

				cln = col(xr[j],nw,X);
				
				cnt[cln] -= (xr[j] - z + 1);
				
				continue;
			}

			int pos = xr[j] - (xr[j] % X) + 1;
			int cln = col(z,nw,X);
			
			cnt[cln] -= ((pos - z) / X + 1)/2 * X;
			cnt[cln ^ 1] -= ((pos-z)/X)/2 * X;
			
			cln = col(xl[j],nw,X);
			
			cnt[cln] -= (z - xl[j]);

			cln = col(xr[j],nw,X);
			
			cnt[cln] -= (xr[j] - pos + 1);
		}
	}
	// cout<<X<<' '<<tp<<' '<<now<<'\n';
	return now;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> k;
	for(int i = 1;i <= k;i++){
		cin >> xl[i] >> yl[i] >> xr[i] >> yr[i];
		v[yl[i]].push_back(i);
		p[yr[i]].push_back(i);
	}
	ll ans = 1ll * n * n;
	for(int i = 1;i < n;i++) if(n % i == 0){
		ans=min(ans,f(i,0));
		ans=min(ans,f(i,1));
	}
	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Incorrect 2 ms 4940 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 8860 KB Output is correct
2 Incorrect 11 ms 6180 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 8860 KB Output is correct
2 Incorrect 11 ms 6180 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Incorrect 2 ms 4940 KB Output isn't correct
3 Halted 0 ms 0 KB -