제출 #684227

#제출 시각아이디문제언어결과실행 시간메모리
684227mychecksedadChessboard (IZhO18_chessboard)C++17
47 / 100
2025 ms5064 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define all(x) x.begin() x.end()
#define MOD (1e9+7)
const int N = 1e6;

ll n, k, ans = 1e18;
vector<array<ll, 4>> vv;

ll wh(ll x, ll y, ll d){
	x++, y++;
	if(x <= 0 || y <= 0) return 0;
	ll res = (x / d) * (y / d) / 2 * d * d;
	if(x % (2*d) >= d){
		ll y1 = y / (2*d) * 2*d;
		res += y1 / (2*d) * (x % d) * d;
		res += (x % d) * min(d, y % (2*d));
	}else{
		ll y1 = y / (2*d) * 2*d;
		res += y1 / (2*d) * (x % d) * d;
	}
	if(y % (2*d) >= d){
		ll x1 = x / (2*d) * 2*d;
		res += x1 / (2*d) * (y % d) * d;
		res += (y % d) * min(d, x % (2*d));
	}else{
		ll x1 = x / (2*d) * 2*d;
		res += x1 / (2*d) * (y % d) * d;
	}
	return res;
}
ll bl(ll x, ll y, ll d){
	x++, y++;
	if(x <= 0 || y <= 0) return 0;
	return x * y - wh(x - 1, y - 1, d);
}
void solve(){
	cin >> n >> k;
	int a = 0;
	for(int i = 0; i < k; ++i){
		int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2;
		vv.pb({x1-1,y1-1,x2-1,y2-1});
	}
	for(ll i = 1; i < n; ++i){
		if(n % i == 0){
			for(int rep = 0; rep < 2; ++rep){
				ll c = 0;
				for(auto v: vv){
					ll white = wh(v[2], v[3], i) - wh(v[0] - 1, v[3], i) - wh(v[2], v[1] - 1, i) + wh(v[0] - 1, v[1] - 1, i);					
					ll black = bl(v[2], v[3], i) - bl(v[0] - 1, v[3], i) - bl(v[2], v[1] - 1, i) + bl(v[0] - 1, v[1] - 1, i);					
					ll val = white - black;
					if(!rep) c += val;
					else c -= val;
				}
				ans = min(ans, c + (rep ? (n/i)*(n/i)/2*i*i : ((n/i)*(n/i) + 1)/2*i*i));
			}

		}
	}
	cout << ans;
}

int main(){
	solve();
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

chessboard.cpp: In function 'void solve()':
chessboard.cpp:41:6: warning: unused variable 'a' [-Wunused-variable]
   41 |  int a = 0;
      |      ^
#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...