#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
using namespace std;
pair <ll,ll> a[100001];
int main()
{
ll n,m,i,j;
cin>>n>>m;
for(i=1;i<=m;i++)
{
ll x,y;
cin>>x>>x>>x>>y;
a[i]={x,y};
}
ll ans=1e10;
for(i=1;i<=sqrt(n);i++)
{
if (n%i==0)
{
ll raz=i;ll izm=0;
ll kolb=(((n*n)/(i*i)))/2*i*i;
ll kolw=((((n*n)/(i*i)))/2+(((n*n)/(i*i))%2))*i*i;
for(ll j=1;j<=m;j++)
{
ll x=(a[j].fr/i)+(a[j].fr%i>0),y=(a[j].sc/i)+(a[j].sc%i>0);
if ((x+y)%2==1)
izm++;
}
ans=min(ans,min(izm+(kolw-(m-izm)),(m-izm)+(kolb-izm)));
//cout<<ans<<" "<<i<<" "<<izm<<" "<<kolb<<" "<<kolw<<endl;
if (i==1) continue;
raz=i;
i=n/i;
izm=0;
kolb=(((n*n)/(i*i)))/2*i*i;
kolw=((((n*n)/(i*i)))/2+(((n*n)/(i*i))%2))*i*i;
for(ll j=1;j<=m;j++)
{
ll x=a[j].fr/i+(a[j].fr%i>0),y=(a[j].sc/i)+(a[j].sc%i>0);
if ((x+y)%2==1)
izm++;
}
ans=min(ans,min(izm+(kolw-(m-izm)),(m-izm)+(kolb-izm)));
//cout<<ans<<" "<<i<<" "<<izm<<endl;
i=raz;
}
}
cout<<ans;
return 0;
}
/*
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
*/
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:9:14: warning: unused variable 'j' [-Wunused-variable]
ll n,m,i,j;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
1400 KB |
Output is correct |
2 |
Correct |
23 ms |
1400 KB |
Output is correct |
3 |
Correct |
55 ms |
1400 KB |
Output is correct |
4 |
Correct |
56 ms |
1400 KB |
Output is correct |
5 |
Correct |
75 ms |
1400 KB |
Output is correct |
6 |
Correct |
49 ms |
1400 KB |
Output is correct |
7 |
Correct |
12 ms |
1400 KB |
Output is correct |
8 |
Correct |
62 ms |
1400 KB |
Output is correct |
9 |
Correct |
124 ms |
1908 KB |
Output is correct |
10 |
Correct |
69 ms |
1908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1908 KB |
Output is correct |
2 |
Correct |
2 ms |
1908 KB |
Output is correct |
3 |
Correct |
3 ms |
1908 KB |
Output is correct |
4 |
Correct |
4 ms |
1908 KB |
Output is correct |
5 |
Correct |
3 ms |
1908 KB |
Output is correct |
6 |
Correct |
3 ms |
1908 KB |
Output is correct |
7 |
Correct |
4 ms |
1908 KB |
Output is correct |
8 |
Correct |
2 ms |
1908 KB |
Output is correct |
9 |
Correct |
2 ms |
1908 KB |
Output is correct |
10 |
Correct |
2 ms |
1908 KB |
Output is correct |
11 |
Correct |
2 ms |
1908 KB |
Output is correct |
12 |
Correct |
2 ms |
1908 KB |
Output is correct |
13 |
Correct |
3 ms |
1908 KB |
Output is correct |
14 |
Correct |
3 ms |
1908 KB |
Output is correct |
15 |
Correct |
3 ms |
1908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1908 KB |
Output is correct |
2 |
Correct |
2 ms |
1908 KB |
Output is correct |
3 |
Correct |
3 ms |
1908 KB |
Output is correct |
4 |
Correct |
4 ms |
1908 KB |
Output is correct |
5 |
Correct |
3 ms |
1908 KB |
Output is correct |
6 |
Correct |
3 ms |
1908 KB |
Output is correct |
7 |
Correct |
4 ms |
1908 KB |
Output is correct |
8 |
Correct |
2 ms |
1908 KB |
Output is correct |
9 |
Correct |
2 ms |
1908 KB |
Output is correct |
10 |
Correct |
2 ms |
1908 KB |
Output is correct |
11 |
Correct |
2 ms |
1908 KB |
Output is correct |
12 |
Correct |
2 ms |
1908 KB |
Output is correct |
13 |
Correct |
3 ms |
1908 KB |
Output is correct |
14 |
Correct |
3 ms |
1908 KB |
Output is correct |
15 |
Correct |
3 ms |
1908 KB |
Output is correct |
16 |
Correct |
35 ms |
1908 KB |
Output is correct |
17 |
Correct |
89 ms |
1908 KB |
Output is correct |
18 |
Correct |
116 ms |
2176 KB |
Output is correct |
19 |
Correct |
162 ms |
2176 KB |
Output is correct |
20 |
Correct |
172 ms |
2176 KB |
Output is correct |
21 |
Correct |
83 ms |
2176 KB |
Output is correct |
22 |
Correct |
2 ms |
2176 KB |
Output is correct |
23 |
Correct |
54 ms |
2176 KB |
Output is correct |
24 |
Correct |
111 ms |
2176 KB |
Output is correct |
25 |
Correct |
13 ms |
2176 KB |
Output is correct |
26 |
Correct |
95 ms |
2176 KB |
Output is correct |
27 |
Correct |
77 ms |
2176 KB |
Output is correct |
28 |
Correct |
108 ms |
2176 KB |
Output is correct |
29 |
Correct |
52 ms |
2176 KB |
Output is correct |
30 |
Correct |
5 ms |
2176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
1400 KB |
Output is correct |
2 |
Correct |
23 ms |
1400 KB |
Output is correct |
3 |
Correct |
55 ms |
1400 KB |
Output is correct |
4 |
Correct |
56 ms |
1400 KB |
Output is correct |
5 |
Correct |
75 ms |
1400 KB |
Output is correct |
6 |
Correct |
49 ms |
1400 KB |
Output is correct |
7 |
Correct |
12 ms |
1400 KB |
Output is correct |
8 |
Correct |
62 ms |
1400 KB |
Output is correct |
9 |
Correct |
124 ms |
1908 KB |
Output is correct |
10 |
Correct |
69 ms |
1908 KB |
Output is correct |
11 |
Correct |
2 ms |
1908 KB |
Output is correct |
12 |
Correct |
2 ms |
1908 KB |
Output is correct |
13 |
Correct |
3 ms |
1908 KB |
Output is correct |
14 |
Correct |
4 ms |
1908 KB |
Output is correct |
15 |
Correct |
3 ms |
1908 KB |
Output is correct |
16 |
Correct |
3 ms |
1908 KB |
Output is correct |
17 |
Correct |
4 ms |
1908 KB |
Output is correct |
18 |
Correct |
2 ms |
1908 KB |
Output is correct |
19 |
Correct |
2 ms |
1908 KB |
Output is correct |
20 |
Correct |
2 ms |
1908 KB |
Output is correct |
21 |
Correct |
2 ms |
1908 KB |
Output is correct |
22 |
Correct |
2 ms |
1908 KB |
Output is correct |
23 |
Correct |
3 ms |
1908 KB |
Output is correct |
24 |
Correct |
3 ms |
1908 KB |
Output is correct |
25 |
Correct |
3 ms |
1908 KB |
Output is correct |
26 |
Correct |
35 ms |
1908 KB |
Output is correct |
27 |
Correct |
89 ms |
1908 KB |
Output is correct |
28 |
Correct |
116 ms |
2176 KB |
Output is correct |
29 |
Correct |
162 ms |
2176 KB |
Output is correct |
30 |
Correct |
172 ms |
2176 KB |
Output is correct |
31 |
Correct |
83 ms |
2176 KB |
Output is correct |
32 |
Correct |
2 ms |
2176 KB |
Output is correct |
33 |
Correct |
54 ms |
2176 KB |
Output is correct |
34 |
Correct |
111 ms |
2176 KB |
Output is correct |
35 |
Correct |
13 ms |
2176 KB |
Output is correct |
36 |
Correct |
95 ms |
2176 KB |
Output is correct |
37 |
Correct |
77 ms |
2176 KB |
Output is correct |
38 |
Correct |
108 ms |
2176 KB |
Output is correct |
39 |
Correct |
52 ms |
2176 KB |
Output is correct |
40 |
Correct |
5 ms |
2176 KB |
Output is correct |
41 |
Correct |
174 ms |
2176 KB |
Output is correct |
42 |
Correct |
139 ms |
2176 KB |
Output is correct |
43 |
Correct |
137 ms |
2176 KB |
Output is correct |
44 |
Correct |
131 ms |
2176 KB |
Output is correct |
45 |
Correct |
174 ms |
2176 KB |
Output is correct |
46 |
Correct |
185 ms |
2176 KB |
Output is correct |
47 |
Correct |
139 ms |
2176 KB |
Output is correct |
48 |
Correct |
135 ms |
2176 KB |
Output is correct |
49 |
Correct |
126 ms |
2176 KB |
Output is correct |
50 |
Correct |
449 ms |
2176 KB |
Output is correct |
51 |
Correct |
472 ms |
2244 KB |
Output is correct |
52 |
Correct |
478 ms |
2244 KB |
Output is correct |
53 |
Correct |
482 ms |
2244 KB |
Output is correct |
54 |
Correct |
462 ms |
2244 KB |
Output is correct |
55 |
Correct |
498 ms |
2304 KB |
Output is correct |
56 |
Correct |
418 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
86 ms |
1400 KB |
Output is correct |
10 |
Correct |
23 ms |
1400 KB |
Output is correct |
11 |
Correct |
55 ms |
1400 KB |
Output is correct |
12 |
Correct |
56 ms |
1400 KB |
Output is correct |
13 |
Correct |
75 ms |
1400 KB |
Output is correct |
14 |
Correct |
49 ms |
1400 KB |
Output is correct |
15 |
Correct |
12 ms |
1400 KB |
Output is correct |
16 |
Correct |
62 ms |
1400 KB |
Output is correct |
17 |
Correct |
124 ms |
1908 KB |
Output is correct |
18 |
Correct |
69 ms |
1908 KB |
Output is correct |
19 |
Correct |
2 ms |
1908 KB |
Output is correct |
20 |
Correct |
2 ms |
1908 KB |
Output is correct |
21 |
Correct |
3 ms |
1908 KB |
Output is correct |
22 |
Correct |
4 ms |
1908 KB |
Output is correct |
23 |
Correct |
3 ms |
1908 KB |
Output is correct |
24 |
Correct |
3 ms |
1908 KB |
Output is correct |
25 |
Correct |
4 ms |
1908 KB |
Output is correct |
26 |
Correct |
2 ms |
1908 KB |
Output is correct |
27 |
Correct |
2 ms |
1908 KB |
Output is correct |
28 |
Correct |
2 ms |
1908 KB |
Output is correct |
29 |
Correct |
2 ms |
1908 KB |
Output is correct |
30 |
Correct |
2 ms |
1908 KB |
Output is correct |
31 |
Correct |
3 ms |
1908 KB |
Output is correct |
32 |
Correct |
3 ms |
1908 KB |
Output is correct |
33 |
Correct |
3 ms |
1908 KB |
Output is correct |
34 |
Correct |
35 ms |
1908 KB |
Output is correct |
35 |
Correct |
89 ms |
1908 KB |
Output is correct |
36 |
Correct |
116 ms |
2176 KB |
Output is correct |
37 |
Correct |
162 ms |
2176 KB |
Output is correct |
38 |
Correct |
172 ms |
2176 KB |
Output is correct |
39 |
Correct |
83 ms |
2176 KB |
Output is correct |
40 |
Correct |
2 ms |
2176 KB |
Output is correct |
41 |
Correct |
54 ms |
2176 KB |
Output is correct |
42 |
Correct |
111 ms |
2176 KB |
Output is correct |
43 |
Correct |
13 ms |
2176 KB |
Output is correct |
44 |
Correct |
95 ms |
2176 KB |
Output is correct |
45 |
Correct |
77 ms |
2176 KB |
Output is correct |
46 |
Correct |
108 ms |
2176 KB |
Output is correct |
47 |
Correct |
52 ms |
2176 KB |
Output is correct |
48 |
Correct |
5 ms |
2176 KB |
Output is correct |
49 |
Correct |
174 ms |
2176 KB |
Output is correct |
50 |
Correct |
139 ms |
2176 KB |
Output is correct |
51 |
Correct |
137 ms |
2176 KB |
Output is correct |
52 |
Correct |
131 ms |
2176 KB |
Output is correct |
53 |
Correct |
174 ms |
2176 KB |
Output is correct |
54 |
Correct |
185 ms |
2176 KB |
Output is correct |
55 |
Correct |
139 ms |
2176 KB |
Output is correct |
56 |
Correct |
135 ms |
2176 KB |
Output is correct |
57 |
Correct |
126 ms |
2176 KB |
Output is correct |
58 |
Correct |
449 ms |
2176 KB |
Output is correct |
59 |
Correct |
472 ms |
2244 KB |
Output is correct |
60 |
Correct |
478 ms |
2244 KB |
Output is correct |
61 |
Correct |
482 ms |
2244 KB |
Output is correct |
62 |
Correct |
462 ms |
2244 KB |
Output is correct |
63 |
Correct |
498 ms |
2304 KB |
Output is correct |
64 |
Correct |
418 ms |
2304 KB |
Output is correct |
65 |
Correct |
2 ms |
2304 KB |
Output is correct |
66 |
Incorrect |
2 ms |
2304 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |