제출 #202243

#제출 시각아이디문제언어결과실행 시간메모리
202243ZwariowanyMarcinChessboard (IZhO18_chessboard)C++14
39 / 100
203 ms3448 KiB
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl

using namespace std;

const int nax = 1e5 + 11;
const LL INF = 1e18;

int n, k;
LL best = INF;

struct pt {
	int x, y, xx, yy;
};

pt t[nax];
		
LL rec(int bok, int x, int y) {
	int X = x / bok;
	int Y = y / bok;
	LL black = 0;
	if (X % 2 == 0 || Y % 2 == 0) {
		black += (LL) X * Y / 2 * bok * bok;
	}
	else {
		black += (LL) ((X * Y) / 2 + 1) * bok * bok;
	}
	if (X % 2 == Y % 2) {
		black += (LL) (x - X * bok) * (y - Y * bok);
	}
	if (Y % 2 == 0) {
		black += (LL) (X + 1) / 2 * (y - Y * bok) * bok;
	}
	else {
		black += (LL) X / 2 * (y - Y * bok) * bok;
	}
	if (X % 2 == 0) {
		black += (LL) (Y + 1) / 2 * (x - X * bok) * bok;
	}
	else {
		black += (LL) Y / 2 * (x - X * bok) * bok;
	}
	return black;
}												
	
void solve(int bok) {
	LL sum = 0;
	LL pole = 0;
	for (int i = 0; i < k; ++i) {
		sum += rec(bok, t[i].xx, t[i].yy) - rec(bok, t[i].x - 1, t[i].yy) - rec(bok, t[i].xx, t[i].y - 1) + rec(bok, t[i].x - 1, t[i].y - 1);
		pole += (LL) (t[i].xx - t[i].x + 1) * (t[i].yy - t[i].y + 1);
	}
	LL black = rec(bok, n, n);
	LL white = (LL) n * n - black;
	/*if (bok == 2) {
		cat(rec(2, t[0].x - 1, t[0].yy));
		cat(black);
		cat(white);
		cat(sum);
		cat(pole);
	}
	*/
	best = min(best, (black - sum) + (pole - sum));
	best = min(best, (white - (pole - sum)) + sum);
}
	

int main() {		
	scanf ("%d%d", &n, &k);
	for (int i = 0; i < k; ++i) 
		scanf ("%d %d %d %d", &t[i].x, &t[i].y, &t[i].xx, &t[i].yy);
		
	for (int i = 1; i < n; ++i)
		if (n % i == 0) solve(i);
		
	printf ("%lld", best);
	
	return 0;
}

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

chessboard.cpp: In function 'int main()':
chessboard.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d", &n, &k);
  ~~~~~~^~~~~~~~~~~~~~~~
chessboard.cpp:77:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d %d %d", &t[i].x, &t[i].y, &t[i].xx, &t[i].yy);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...