#include <bits/stdc++.h>
using namespace std;
int n,k,i,x,y,x2,y2;
struct dreptunghi{
int x,y,x2,y2;
};
vector <dreptunghi> v;
long long count_(int x, int y, int val){
if (!x || !y)
return 0;
long long sol = 1LL * (x/val) * (y/val) / 2 * val * val;
int lastx = (x/val) * val, lasty = (y/val) * val;
if (x/val % 2)
sol += (y/val + 1)/2 * val * (x - lastx);
else sol += (y/val/2) * val * (x - lastx);
if (y/val % 2)
sol += (x/val + 1)/2 * val * (y - lasty);
else sol += (x/val/2) * val * (y - lasty);
if (!(x/val % 2 == y/val%2))
sol += (x - lastx) * (y - lasty);
return sol;
}
long long solve (int val){
long long albe = 1LL * (n/val) * (n/val) / 2 * val * val; /// cate ar trebui sa fac albe daca e toata tabla neagra
long long negre = 1LL * n * n - albe;
for (auto it : v){
int x = it.x, y = it.y, x2 = it.x2, y2 = it.y2;
long long cnt = count_(x2,y2,val) - count_(x2,y-1,val) - count_(x-1,y2,val) + count_(x-1,y-1,val);
negre -= (x2-x+1) * (y2-y+1) - cnt; /// nu are sens sa le fac pe astea negre
negre += cnt; /// trb sa le fac la loc albe pe astea
albe += (x2-x+1) * (y2-y+1) - cnt;
albe -= cnt;
}
return min (albe,negre);
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>k;
for (i=1;i<=k;i++){
cin>>x>>y>>x2>>y2;
v.push_back({x,y,x2,y2});
}
long long sol = 1LL * n * n;
for (int d=1;d<n;d++){
if (n % d == 0)
sol = min (sol,solve(d));
}
cout<<sol;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
2912 KB |
Output is correct |
2 |
Correct |
20 ms |
1256 KB |
Output is correct |
3 |
Correct |
52 ms |
2404 KB |
Output is correct |
4 |
Correct |
51 ms |
2276 KB |
Output is correct |
5 |
Correct |
71 ms |
2656 KB |
Output is correct |
6 |
Correct |
45 ms |
2276 KB |
Output is correct |
7 |
Correct |
10 ms |
748 KB |
Output is correct |
8 |
Correct |
47 ms |
2416 KB |
Output is correct |
9 |
Correct |
115 ms |
4192 KB |
Output is correct |
10 |
Correct |
63 ms |
2532 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 |
2 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 |
2 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 |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 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 |
2 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 |
2 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 |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
33 ms |
1512 KB |
Output is correct |
17 |
Correct |
86 ms |
3808 KB |
Output is correct |
18 |
Correct |
111 ms |
3808 KB |
Output is correct |
19 |
Correct |
222 ms |
3808 KB |
Output is correct |
20 |
Correct |
249 ms |
3936 KB |
Output is correct |
21 |
Correct |
83 ms |
3800 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
59 ms |
2148 KB |
Output is correct |
24 |
Correct |
106 ms |
3808 KB |
Output is correct |
25 |
Correct |
12 ms |
788 KB |
Output is correct |
26 |
Correct |
64 ms |
2276 KB |
Output is correct |
27 |
Correct |
86 ms |
3552 KB |
Output is correct |
28 |
Correct |
108 ms |
3808 KB |
Output is correct |
29 |
Correct |
34 ms |
2020 KB |
Output is correct |
30 |
Correct |
4 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
2912 KB |
Output is correct |
2 |
Correct |
20 ms |
1256 KB |
Output is correct |
3 |
Correct |
52 ms |
2404 KB |
Output is correct |
4 |
Correct |
51 ms |
2276 KB |
Output is correct |
5 |
Correct |
71 ms |
2656 KB |
Output is correct |
6 |
Correct |
45 ms |
2276 KB |
Output is correct |
7 |
Correct |
10 ms |
748 KB |
Output is correct |
8 |
Correct |
47 ms |
2416 KB |
Output is correct |
9 |
Correct |
115 ms |
4192 KB |
Output is correct |
10 |
Correct |
63 ms |
2532 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 |
2 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 |
2 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 |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
33 ms |
1512 KB |
Output is correct |
27 |
Correct |
86 ms |
3808 KB |
Output is correct |
28 |
Correct |
111 ms |
3808 KB |
Output is correct |
29 |
Correct |
222 ms |
3808 KB |
Output is correct |
30 |
Correct |
249 ms |
3936 KB |
Output is correct |
31 |
Correct |
83 ms |
3800 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
59 ms |
2148 KB |
Output is correct |
34 |
Correct |
106 ms |
3808 KB |
Output is correct |
35 |
Correct |
12 ms |
788 KB |
Output is correct |
36 |
Correct |
64 ms |
2276 KB |
Output is correct |
37 |
Correct |
86 ms |
3552 KB |
Output is correct |
38 |
Correct |
108 ms |
3808 KB |
Output is correct |
39 |
Correct |
34 ms |
2020 KB |
Output is correct |
40 |
Correct |
4 ms |
492 KB |
Output is correct |
41 |
Correct |
220 ms |
4320 KB |
Output is correct |
42 |
Correct |
134 ms |
4320 KB |
Output is correct |
43 |
Correct |
159 ms |
4320 KB |
Output is correct |
44 |
Correct |
128 ms |
4320 KB |
Output is correct |
45 |
Correct |
129 ms |
4320 KB |
Output is correct |
46 |
Incorrect |
245 ms |
4320 KB |
Output isn't correct |
47 |
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 |
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 |
80 ms |
2912 KB |
Output is correct |
10 |
Correct |
20 ms |
1256 KB |
Output is correct |
11 |
Correct |
52 ms |
2404 KB |
Output is correct |
12 |
Correct |
51 ms |
2276 KB |
Output is correct |
13 |
Correct |
71 ms |
2656 KB |
Output is correct |
14 |
Correct |
45 ms |
2276 KB |
Output is correct |
15 |
Correct |
10 ms |
748 KB |
Output is correct |
16 |
Correct |
47 ms |
2416 KB |
Output is correct |
17 |
Correct |
115 ms |
4192 KB |
Output is correct |
18 |
Correct |
63 ms |
2532 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 |
2 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 |
2 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 |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
2 ms |
364 KB |
Output is correct |
34 |
Correct |
33 ms |
1512 KB |
Output is correct |
35 |
Correct |
86 ms |
3808 KB |
Output is correct |
36 |
Correct |
111 ms |
3808 KB |
Output is correct |
37 |
Correct |
222 ms |
3808 KB |
Output is correct |
38 |
Correct |
249 ms |
3936 KB |
Output is correct |
39 |
Correct |
83 ms |
3800 KB |
Output is correct |
40 |
Correct |
1 ms |
384 KB |
Output is correct |
41 |
Correct |
59 ms |
2148 KB |
Output is correct |
42 |
Correct |
106 ms |
3808 KB |
Output is correct |
43 |
Correct |
12 ms |
788 KB |
Output is correct |
44 |
Correct |
64 ms |
2276 KB |
Output is correct |
45 |
Correct |
86 ms |
3552 KB |
Output is correct |
46 |
Correct |
108 ms |
3808 KB |
Output is correct |
47 |
Correct |
34 ms |
2020 KB |
Output is correct |
48 |
Correct |
4 ms |
492 KB |
Output is correct |
49 |
Correct |
220 ms |
4320 KB |
Output is correct |
50 |
Correct |
134 ms |
4320 KB |
Output is correct |
51 |
Correct |
159 ms |
4320 KB |
Output is correct |
52 |
Correct |
128 ms |
4320 KB |
Output is correct |
53 |
Correct |
129 ms |
4320 KB |
Output is correct |
54 |
Incorrect |
245 ms |
4320 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |