/** kutbilim.one **/
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define int long long
#define endl '\n'
/*
ifstream in("test.txt");
#define cin in
const signed MAX = 1001;
vector< vector<signed> > a(MAX, vector<signed> (MAX, 0));
*/
int n, k;
bool isprime(int n){
if(n == 2) return true;
for(int i = 2; i*i <= n; i++)
if(n%i == 0) return false;
return true;
}
void solve_1(){
int result = INT_MAX;
for(int i = 1; i < n; i++){
if(n%i) continue;
result = min(result, ((n*n)/(i*i)/2)*(i*i));
}
cout << result;
}
void solve_2(){
int cnt[2] = {0, 0};
for(int i = 1; i <= k; i++){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
for(int x = x1; x <= x2; x++)
for(int y = y1; y <= y2; y++){
//a[x][y] = 1;
cnt[(x+y)%2]++;
}
}
cout << min(n*n/2-cnt[1] + cnt[0], n*n/2+1-cnt[0] + cnt[1]);
}
void solve_3_4(){
vector<pair<int, int>> sides(n, {0, 0});
vector<int> f;
for(int i = 1; i*i <= n; i++){
if(n % i == 0){
f.push_back(i);
if(i != 1) f.push_back(n/i);
}
}
for(int i = 1; i <= k; i++){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
for(int x = x1; x <= x2; x++)
for(int y = y1; y <= y2; y++){
//a[x][y] = 1;
for(auto d : f){
if(((x+d-1)/d+(y+d-1)/d) % 2) sides[d].first++;
else sides[d].second++;
}
}
}
int result = LONG_MAX;
for(auto d : f){
result = min(
result,
((n*n)/(d*d)/2)*(d*d)+(d*d) - sides[d].second + sides[d].first
);
result = min(
result,
((n*n)/(d*d)/2)*(d*d) - sides[d].first + sides[d].second
);
}
cout << result;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
if(k == 0){
solve_1();
}else if(isprime(n)){
solve_2();
}else{
solve_3_4();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
364 KB |
Output is correct |
3 |
Correct |
16 ms |
364 KB |
Output is correct |
4 |
Correct |
15 ms |
364 KB |
Output is correct |
5 |
Correct |
19 ms |
364 KB |
Output is correct |
6 |
Correct |
12 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 |
34 ms |
364 KB |
Output is correct |
10 |
Correct |
18 ms |
384 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 |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 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 |
384 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
384 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 |
384 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 |
364 KB |
Output is correct |
17 |
Correct |
25 ms |
364 KB |
Output is correct |
18 |
Correct |
34 ms |
364 KB |
Output is correct |
19 |
Correct |
65 ms |
364 KB |
Output is correct |
20 |
Correct |
73 ms |
364 KB |
Output is correct |
21 |
Correct |
24 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
17 ms |
364 KB |
Output is correct |
24 |
Correct |
30 ms |
364 KB |
Output is correct |
25 |
Correct |
4 ms |
364 KB |
Output is correct |
26 |
Correct |
19 ms |
364 KB |
Output is correct |
27 |
Correct |
25 ms |
364 KB |
Output is correct |
28 |
Correct |
32 ms |
364 KB |
Output is correct |
29 |
Correct |
10 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
364 KB |
Output is correct |
3 |
Correct |
16 ms |
364 KB |
Output is correct |
4 |
Correct |
15 ms |
364 KB |
Output is correct |
5 |
Correct |
19 ms |
364 KB |
Output is correct |
6 |
Correct |
12 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 |
34 ms |
364 KB |
Output is correct |
10 |
Correct |
18 ms |
384 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 |
384 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 |
384 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 |
364 KB |
Output is correct |
27 |
Correct |
25 ms |
364 KB |
Output is correct |
28 |
Correct |
34 ms |
364 KB |
Output is correct |
29 |
Correct |
65 ms |
364 KB |
Output is correct |
30 |
Correct |
73 ms |
364 KB |
Output is correct |
31 |
Correct |
24 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
17 ms |
364 KB |
Output is correct |
34 |
Correct |
30 ms |
364 KB |
Output is correct |
35 |
Correct |
4 ms |
364 KB |
Output is correct |
36 |
Correct |
19 ms |
364 KB |
Output is correct |
37 |
Correct |
25 ms |
364 KB |
Output is correct |
38 |
Correct |
32 ms |
364 KB |
Output is correct |
39 |
Correct |
10 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
64 ms |
1900 KB |
Output is correct |
42 |
Correct |
39 ms |
4204 KB |
Output is correct |
43 |
Correct |
46 ms |
3948 KB |
Output is correct |
44 |
Correct |
38 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 |
30 ms |
2412 KB |
Output is correct |
48 |
Correct |
42 ms |
3948 KB |
Output is correct |
49 |
Correct |
35 ms |
3948 KB |
Output is correct |
50 |
Correct |
235 ms |
3948 KB |
Output is correct |
51 |
Correct |
249 ms |
4096 KB |
Output is correct |
52 |
Correct |
259 ms |
3820 KB |
Output is correct |
53 |
Correct |
248 ms |
4076 KB |
Output is correct |
54 |
Correct |
229 ms |
3820 KB |
Output is correct |
55 |
Correct |
260 ms |
4204 KB |
Output is correct |
56 |
Correct |
225 ms |
3820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
22 ms |
364 KB |
Output is correct |
10 |
Correct |
6 ms |
364 KB |
Output is correct |
11 |
Correct |
16 ms |
364 KB |
Output is correct |
12 |
Correct |
15 ms |
364 KB |
Output is correct |
13 |
Correct |
19 ms |
364 KB |
Output is correct |
14 |
Correct |
12 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 |
34 ms |
364 KB |
Output is correct |
18 |
Correct |
18 ms |
384 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 |
384 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 |
384 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 |
364 KB |
Output is correct |
35 |
Correct |
25 ms |
364 KB |
Output is correct |
36 |
Correct |
34 ms |
364 KB |
Output is correct |
37 |
Correct |
65 ms |
364 KB |
Output is correct |
38 |
Correct |
73 ms |
364 KB |
Output is correct |
39 |
Correct |
24 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
17 ms |
364 KB |
Output is correct |
42 |
Correct |
30 ms |
364 KB |
Output is correct |
43 |
Correct |
4 ms |
364 KB |
Output is correct |
44 |
Correct |
19 ms |
364 KB |
Output is correct |
45 |
Correct |
25 ms |
364 KB |
Output is correct |
46 |
Correct |
32 ms |
364 KB |
Output is correct |
47 |
Correct |
10 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
1900 KB |
Output is correct |
50 |
Correct |
39 ms |
4204 KB |
Output is correct |
51 |
Correct |
46 ms |
3948 KB |
Output is correct |
52 |
Correct |
38 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 |
30 ms |
2412 KB |
Output is correct |
56 |
Correct |
42 ms |
3948 KB |
Output is correct |
57 |
Correct |
35 ms |
3948 KB |
Output is correct |
58 |
Correct |
235 ms |
3948 KB |
Output is correct |
59 |
Correct |
249 ms |
4096 KB |
Output is correct |
60 |
Correct |
259 ms |
3820 KB |
Output is correct |
61 |
Correct |
248 ms |
4076 KB |
Output is correct |
62 |
Correct |
229 ms |
3820 KB |
Output is correct |
63 |
Correct |
260 ms |
4204 KB |
Output is correct |
64 |
Correct |
225 ms |
3820 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
1 ms |
364 KB |
Output is correct |
67 |
Execution timed out |
2088 ms |
1644 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |