Submission #907410

# Submission time Handle Problem Language Result Execution time Memory
907410 2024-01-15T13:49:47 Z daoquanglinh2007 Chessboard (IZhO18_chessboard) C++17
8 / 100
9 ms 2140 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int NM = 1e5, inf = 1e18;

int N, K, x[NM+5], y[NM+5], ans = +inf;
int num[2];

void solve(int t){
	num[0] = num[1] = 0;
	for (int i = 1; i <= K; i++){
		int blx = x[i]/t+(x[i]%t > 0), bly = y[i]/t+(y[i]%t > 0);
		num[(blx+bly)%2]++;
	}
	int targ;
	targ = t*t*(N*N/(t*t)/2);
	ans = min(ans, abs(targ-num[0])+num[1]);
	ans = min(ans, abs(targ-num[1])+num[0]);
	ans = min(ans, abs(N*N-targ-num[0])+num[1]);
	ans = min(ans, abs(N*N-targ-num[1])+num[0]);
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> K;
	for (int i = 1; i <= K; i++){
		cin >> x[i] >> y[i];
	}
	for (int i = 1; i*i <= N; i++)
		if (N%i == 0){
			solve(i);
			if (i > 1) solve(N/i);
		}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 2140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 2140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 9 ms 2140 KB Output isn't correct
10 Halted 0 ms 0 KB -