#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;
int n, k;
vector<vector<bool>> v;
void solve(){
cin >> n >> k;
int a = 0;
for(int i = 1; i <= sqrt(n); ++i){
if(n % i == 0) a++;
}
if(a == 1){
int c1 = 0, c2 = 0;
for(int i = 0; i < k; ++i){
int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2;
int val = x1-1+y1-1;
if(val%2) c1++;
else c2++;
}
cout << min(c1 + ll(n)*n/2 + 1 - c2, c2 + ll(n)*n/2 - c1);
return;
}
v.resize(n);
for(int i = 0; i < n; ++i) v[i].resize(n);
for(int i = 0; i < k; ++i){
int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2;
v[x1 - 1][y1 - 1] = 1;
}
int ans = MOD;
for(int i = 1; i < n; ++i){
if(n % i == 0){
for(int rep = 0; rep < 2; ++rep){
int c = 0;
for(int jx = 0; jx < n; ++jx){
for(int jy = 0; jy < n; ++jy){
int val = jx/i + jy/i;
c += (val%2)^rep^v[jx][jy];
}
}
ans = min(ans, c);
}
}
}
cout << ans;
}
int main(){
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
1684 KB |
Output is correct |
2 |
Correct |
16 ms |
596 KB |
Output is correct |
3 |
Correct |
43 ms |
1104 KB |
Output is correct |
4 |
Correct |
45 ms |
1068 KB |
Output is correct |
5 |
Correct |
59 ms |
1540 KB |
Output is correct |
6 |
Correct |
34 ms |
1100 KB |
Output is correct |
7 |
Correct |
7 ms |
340 KB |
Output is correct |
8 |
Correct |
45 ms |
1024 KB |
Output is correct |
9 |
Correct |
97 ms |
2304 KB |
Output is correct |
10 |
Correct |
57 ms |
1416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
55 ms |
340 KB |
Output is correct |
17 |
Correct |
65 ms |
284 KB |
Output is correct |
18 |
Correct |
108 ms |
468 KB |
Output is correct |
19 |
Correct |
322 ms |
428 KB |
Output is correct |
20 |
Correct |
321 ms |
432 KB |
Output is correct |
21 |
Correct |
70 ms |
212 KB |
Output is correct |
22 |
Correct |
171 ms |
468 KB |
Output is correct |
23 |
Correct |
106 ms |
448 KB |
Output is correct |
24 |
Correct |
107 ms |
468 KB |
Output is correct |
25 |
Correct |
78 ms |
468 KB |
Output is correct |
26 |
Correct |
88 ms |
428 KB |
Output is correct |
27 |
Correct |
106 ms |
444 KB |
Output is correct |
28 |
Correct |
104 ms |
432 KB |
Output is correct |
29 |
Correct |
27 ms |
276 KB |
Output is correct |
30 |
Correct |
34 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
1684 KB |
Output is correct |
2 |
Correct |
16 ms |
596 KB |
Output is correct |
3 |
Correct |
43 ms |
1104 KB |
Output is correct |
4 |
Correct |
45 ms |
1068 KB |
Output is correct |
5 |
Correct |
59 ms |
1540 KB |
Output is correct |
6 |
Correct |
34 ms |
1100 KB |
Output is correct |
7 |
Correct |
7 ms |
340 KB |
Output is correct |
8 |
Correct |
45 ms |
1024 KB |
Output is correct |
9 |
Correct |
97 ms |
2304 KB |
Output is correct |
10 |
Correct |
57 ms |
1416 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
296 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
55 ms |
340 KB |
Output is correct |
27 |
Correct |
65 ms |
284 KB |
Output is correct |
28 |
Correct |
108 ms |
468 KB |
Output is correct |
29 |
Correct |
322 ms |
428 KB |
Output is correct |
30 |
Correct |
321 ms |
432 KB |
Output is correct |
31 |
Correct |
70 ms |
212 KB |
Output is correct |
32 |
Correct |
171 ms |
468 KB |
Output is correct |
33 |
Correct |
106 ms |
448 KB |
Output is correct |
34 |
Correct |
107 ms |
468 KB |
Output is correct |
35 |
Correct |
78 ms |
468 KB |
Output is correct |
36 |
Correct |
88 ms |
428 KB |
Output is correct |
37 |
Correct |
106 ms |
444 KB |
Output is correct |
38 |
Correct |
104 ms |
432 KB |
Output is correct |
39 |
Correct |
27 ms |
276 KB |
Output is correct |
40 |
Correct |
34 ms |
340 KB |
Output is correct |
41 |
Runtime error |
115 ms |
262144 KB |
Execution killed with signal 9 |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
64 ms |
1684 KB |
Output is correct |
10 |
Correct |
16 ms |
596 KB |
Output is correct |
11 |
Correct |
43 ms |
1104 KB |
Output is correct |
12 |
Correct |
45 ms |
1068 KB |
Output is correct |
13 |
Correct |
59 ms |
1540 KB |
Output is correct |
14 |
Correct |
34 ms |
1100 KB |
Output is correct |
15 |
Correct |
7 ms |
340 KB |
Output is correct |
16 |
Correct |
45 ms |
1024 KB |
Output is correct |
17 |
Correct |
97 ms |
2304 KB |
Output is correct |
18 |
Correct |
57 ms |
1416 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
296 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
55 ms |
340 KB |
Output is correct |
35 |
Correct |
65 ms |
284 KB |
Output is correct |
36 |
Correct |
108 ms |
468 KB |
Output is correct |
37 |
Correct |
322 ms |
428 KB |
Output is correct |
38 |
Correct |
321 ms |
432 KB |
Output is correct |
39 |
Correct |
70 ms |
212 KB |
Output is correct |
40 |
Correct |
171 ms |
468 KB |
Output is correct |
41 |
Correct |
106 ms |
448 KB |
Output is correct |
42 |
Correct |
107 ms |
468 KB |
Output is correct |
43 |
Correct |
78 ms |
468 KB |
Output is correct |
44 |
Correct |
88 ms |
428 KB |
Output is correct |
45 |
Correct |
106 ms |
444 KB |
Output is correct |
46 |
Correct |
104 ms |
432 KB |
Output is correct |
47 |
Correct |
27 ms |
276 KB |
Output is correct |
48 |
Correct |
34 ms |
340 KB |
Output is correct |
49 |
Runtime error |
115 ms |
262144 KB |
Execution killed with signal 9 |
50 |
Halted |
0 ms |
0 KB |
- |