#include <bits/stdc++.h>
#define pb push_back
#define LL long long
#define Kultivator ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int LL
using namespace std;
const LL Mxn = 1e6 + 7;
const LL Mod = 1e9 + 7;
const LL Inf = 1e14 + 7;
bool Prime(int N){
bool Used = false;
for(int i = 2; i <= sqrt(N); i++){
if(N % i == 0){
Used = true;
break;
}
}
return Used;
}
bool Get(int x, int y, int d){
return (x / d + y / d) % 2;
}
void Ans1(int N){
int Ans = Mxn;
for(int i = 1; i < N; i++){
if(N % i == 0){
Ans = min(Ans, (N * N) / (2 * i * i) * (i * i));
}
}
cout << Ans;
}
void Ans2(int N, int K){
LL Cnt1 = 0, Cnt2 = 0;
for(int i = 1, x1, y1, x2, y2; i <= K; i++){
cin >> x1 >> y1 >> x2 >> y2;
bool Num = Get(x2, y2, 1);
if(!Num){
Cnt1++;
} else {
Cnt2++;
}
}
cout << min(N * N / 2 - Cnt2 + Cnt1, N * N / 2 + 1 - Cnt1 + Cnt2);
}
void Ans3(int N, int K){
int Ans = LONG_MAX;
vector <int> F;
vector <pair <int, int>> P(N, {0, 0});
for(int i = 1; i <= sqrt(N); i++){
if(N % i == 0){
F.pb(i);
if(N / i != i && i > 1){
F.pb(N / i);
}
}
}
for(int i = 1, x1, y1, x2, y2; i <= K; i++){
cin >> x1 >> y1 >> x2 >> y2;
for(auto i : F){
if(((x1+i-1)/i+(y1+i-1)/i) % 2){
P[i].first++;
} else {
P[i].second++;
}
}
}
for(auto i : F){
Ans = min(Ans, ((N * N) / (2 * i * i)) * (i * i) + (i * i) + P[i].first - P[i].second);
Ans = min(Ans, ((N * N) / (2 * i * i)) * (i * i) - P[i].first + P[i].second);
}
cout << Ans;
}
signed main(){
Kultivator;
LL N, K;
cin >> N >> K;
if(!K){
Ans1(N);
} else if(!Prime(N)){
Ans2(N, K);
} else {
Ans3(N, K);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
364 KB |
Output is correct |
3 |
Correct |
17 ms |
364 KB |
Output is correct |
4 |
Correct |
16 ms |
364 KB |
Output is correct |
5 |
Correct |
20 ms |
364 KB |
Output is correct |
6 |
Correct |
13 ms |
364 KB |
Output is correct |
7 |
Correct |
3 ms |
364 KB |
Output is correct |
8 |
Correct |
13 ms |
364 KB |
Output is correct |
9 |
Correct |
33 ms |
364 KB |
Output is correct |
10 |
Correct |
23 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 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 |
Correct |
1 ms |
364 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 |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 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 |
Correct |
1 ms |
364 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 |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
11 ms |
748 KB |
Output is correct |
17 |
Correct |
27 ms |
1644 KB |
Output is correct |
18 |
Correct |
39 ms |
1900 KB |
Output is correct |
19 |
Correct |
70 ms |
1772 KB |
Output is correct |
20 |
Correct |
78 ms |
1928 KB |
Output is correct |
21 |
Correct |
25 ms |
1644 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
18 ms |
1004 KB |
Output is correct |
24 |
Correct |
36 ms |
1772 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
20 ms |
1260 KB |
Output is correct |
27 |
Correct |
30 ms |
1388 KB |
Output is correct |
28 |
Correct |
39 ms |
1928 KB |
Output is correct |
29 |
Correct |
11 ms |
876 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
364 KB |
Output is correct |
3 |
Correct |
17 ms |
364 KB |
Output is correct |
4 |
Correct |
16 ms |
364 KB |
Output is correct |
5 |
Correct |
20 ms |
364 KB |
Output is correct |
6 |
Correct |
13 ms |
364 KB |
Output is correct |
7 |
Correct |
3 ms |
364 KB |
Output is correct |
8 |
Correct |
13 ms |
364 KB |
Output is correct |
9 |
Correct |
33 ms |
364 KB |
Output is correct |
10 |
Correct |
23 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 |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
11 ms |
748 KB |
Output is correct |
27 |
Correct |
27 ms |
1644 KB |
Output is correct |
28 |
Correct |
39 ms |
1900 KB |
Output is correct |
29 |
Correct |
70 ms |
1772 KB |
Output is correct |
30 |
Correct |
78 ms |
1928 KB |
Output is correct |
31 |
Correct |
25 ms |
1644 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
18 ms |
1004 KB |
Output is correct |
34 |
Correct |
36 ms |
1772 KB |
Output is correct |
35 |
Correct |
4 ms |
492 KB |
Output is correct |
36 |
Correct |
20 ms |
1260 KB |
Output is correct |
37 |
Correct |
30 ms |
1388 KB |
Output is correct |
38 |
Correct |
39 ms |
1928 KB |
Output is correct |
39 |
Correct |
11 ms |
876 KB |
Output is correct |
40 |
Correct |
2 ms |
364 KB |
Output is correct |
41 |
Correct |
65 ms |
3820 KB |
Output is correct |
42 |
Correct |
40 ms |
4204 KB |
Output is correct |
43 |
Correct |
52 ms |
3948 KB |
Output is correct |
44 |
Correct |
39 ms |
4076 KB |
Output is correct |
45 |
Correct |
36 ms |
2668 KB |
Output is correct |
46 |
Correct |
72 ms |
4076 KB |
Output is correct |
47 |
Correct |
32 ms |
2412 KB |
Output is correct |
48 |
Correct |
43 ms |
3948 KB |
Output is correct |
49 |
Correct |
37 ms |
3948 KB |
Output is correct |
50 |
Correct |
238 ms |
3948 KB |
Output is correct |
51 |
Correct |
256 ms |
3948 KB |
Output is correct |
52 |
Correct |
237 ms |
3820 KB |
Output is correct |
53 |
Correct |
255 ms |
4096 KB |
Output is correct |
54 |
Correct |
231 ms |
3692 KB |
Output is correct |
55 |
Correct |
266 ms |
3984 KB |
Output is correct |
56 |
Correct |
228 ms |
3820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
23 ms |
364 KB |
Output is correct |
10 |
Correct |
6 ms |
364 KB |
Output is correct |
11 |
Correct |
17 ms |
364 KB |
Output is correct |
12 |
Correct |
16 ms |
364 KB |
Output is correct |
13 |
Correct |
20 ms |
364 KB |
Output is correct |
14 |
Correct |
13 ms |
364 KB |
Output is correct |
15 |
Correct |
3 ms |
364 KB |
Output is correct |
16 |
Correct |
13 ms |
364 KB |
Output is correct |
17 |
Correct |
33 ms |
364 KB |
Output is correct |
18 |
Correct |
23 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
11 ms |
748 KB |
Output is correct |
35 |
Correct |
27 ms |
1644 KB |
Output is correct |
36 |
Correct |
39 ms |
1900 KB |
Output is correct |
37 |
Correct |
70 ms |
1772 KB |
Output is correct |
38 |
Correct |
78 ms |
1928 KB |
Output is correct |
39 |
Correct |
25 ms |
1644 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
18 ms |
1004 KB |
Output is correct |
42 |
Correct |
36 ms |
1772 KB |
Output is correct |
43 |
Correct |
4 ms |
492 KB |
Output is correct |
44 |
Correct |
20 ms |
1260 KB |
Output is correct |
45 |
Correct |
30 ms |
1388 KB |
Output is correct |
46 |
Correct |
39 ms |
1928 KB |
Output is correct |
47 |
Correct |
11 ms |
876 KB |
Output is correct |
48 |
Correct |
2 ms |
364 KB |
Output is correct |
49 |
Correct |
65 ms |
3820 KB |
Output is correct |
50 |
Correct |
40 ms |
4204 KB |
Output is correct |
51 |
Correct |
52 ms |
3948 KB |
Output is correct |
52 |
Correct |
39 ms |
4076 KB |
Output is correct |
53 |
Correct |
36 ms |
2668 KB |
Output is correct |
54 |
Correct |
72 ms |
4076 KB |
Output is correct |
55 |
Correct |
32 ms |
2412 KB |
Output is correct |
56 |
Correct |
43 ms |
3948 KB |
Output is correct |
57 |
Correct |
37 ms |
3948 KB |
Output is correct |
58 |
Correct |
238 ms |
3948 KB |
Output is correct |
59 |
Correct |
256 ms |
3948 KB |
Output is correct |
60 |
Correct |
237 ms |
3820 KB |
Output is correct |
61 |
Correct |
255 ms |
4096 KB |
Output is correct |
62 |
Correct |
231 ms |
3692 KB |
Output is correct |
63 |
Correct |
266 ms |
3984 KB |
Output is correct |
64 |
Correct |
228 ms |
3820 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |