이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, k, cnt, x, y, xx, yy;
ll a[50005][3][3];
vector <ll> d;
int main()
{
	cin >> n >> k;
	for ( int i = 1; i < n; i ++ ) {
		if ( n % i == 0 ) {
			d.push_back(i);
		}
	}
	for ( int i = 1; i <= k; i ++ ) {
		cin >> x >> y >> xx >> yy;
		ll r, c;
		for ( auto e: d ) {
			r = (x/e) + ( (x%e) && 1 );
			c = (y/e) + ( (y%e) && 1 );
			a[e][r%2][c%2] ++;
		}
	}
	ll ans1, ans2, mn = INT_MAX;
	for ( auto e: d ) {
		ans1 = ans2 = 0;
		for ( int i = 1; i <= (n/e); i ++ ) {
			if ( i % 2 == 1 ) {
				ans1 += (e*e) * ( (n/e) / 2 );
				ans2 += (e*e) * ( ( (n/e) + 1 ) / 2 );
			} else {
				ans1 += (e*e) * ( ( (n/e) + 1 ) / 2 );
				ans2 += (e*e) * ( (n/e) / 2 );
			}
		}
		if ( k != n*n ){
			ans1 = ans1 + a[e][1][1] + a[e][0][0];
			ans2 = ans2 + a[e][1][0] + a[e][0][1];
			ans1 = ans1 - ( a[e][1][0] + a[e][0][1] );
			ans2 = ans2 - ( a[e][1][1] + a[e][0][0] );
		}
		mn = min ( mn, min ( ans1, ans2 ) );
	}
	cout << mn;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |