//
// main.cpp
// torelax
//
// Created by Rakhman on 11/15/20.
//
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer {cout << "NO"; exit(0);}
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)
const long long mxn = 2e6 + 110;
const long long mnn = 1e3 + 2;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long OO = 1e9;
typedef long long llong;
typedef unsigned long long ullong;
using namespace std;
int n, k;
llong ans = inf;
bool black[mnn][mnn];
struct dot{
int left, up, right, down;
}b[mxn];
llong get_color(int x, int y, int d){
return (((x - 1) / d) + ((y - 1) / d)) % 2;
}
llong get(llong x){
llong cnt = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cnt += (get_color(i, j, x) == black[i][j]);
}
}
llong cnt1 = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cnt1 += (get_color(i, j, x) != black[i][j]);
}
}
return min(cnt1, cnt);
}
int main() {
ios;
cin >> n >> k;
for(int i = 1; i <= k; i++){
cin >> b[i].left >> b[i].up >> b[i].right >> b[i].down;
black[b[i].left][b[i].up] = true;
}
for(int i = 1; i <= sqrt(n); i++){
if(n % i == 0){
ans = min(ans, get(i));
//cout << i << ' ' << ans << nl;
if(n / i != i && i != 1){
ans = min(get(n / i), ans);
//cout << n / i << ' ' << ans << nl;
}
}
}
cout << ans;
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
492 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
45 ms |
1644 KB |
Output is correct |
17 |
Correct |
41 ms |
2816 KB |
Output is correct |
18 |
Correct |
70 ms |
2924 KB |
Output is correct |
19 |
Correct |
328 ms |
2796 KB |
Output is correct |
20 |
Correct |
335 ms |
2816 KB |
Output is correct |
21 |
Correct |
41 ms |
2668 KB |
Output is correct |
22 |
Correct |
182 ms |
1132 KB |
Output is correct |
23 |
Correct |
98 ms |
1900 KB |
Output is correct |
24 |
Correct |
66 ms |
2668 KB |
Output is correct |
25 |
Correct |
83 ms |
1388 KB |
Output is correct |
26 |
Correct |
52 ms |
2156 KB |
Output is correct |
27 |
Correct |
78 ms |
2412 KB |
Output is correct |
28 |
Correct |
67 ms |
2832 KB |
Output is correct |
29 |
Correct |
25 ms |
1900 KB |
Output is correct |
30 |
Correct |
38 ms |
1388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
492 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Runtime error |
3 ms |
492 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |