#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int A[100005], B[100005], C[100005], D[100005];
void solve(){
int n, k;
cin >> n >> k;
for(int i=1;i<=k;i++)cin >> A[i] >> B[i] >> C[i] >> D[i];
int ans = 1e18;
for(int i=1;i<n;i++){
if(n%i)continue;
int tmp = ((n / i) * (n / i) / 2 * i * i), tmp2 = (((n / i) * (n / i) + 1) / 2 * i * i);
for(int j=1;j<=k;j++){
// count number of black rows
int lol = (A[j] + i - 1) / i, lol2 = (B[j] + i - 1) / i;
if(lol%2 == lol2%2)tmp2--, tmp++;
else tmp--, tmp2++;
}
//cout << i << ' ' << tmp << ' ' << tmp2 << '\n';
ans = min({ans, tmp, tmp2});
}
cout << ans;
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message
chessboard.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
34 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
4444 KB |
Output is correct |
2 |
Correct |
6 ms |
3032 KB |
Output is correct |
3 |
Correct |
12 ms |
3932 KB |
Output is correct |
4 |
Correct |
12 ms |
3676 KB |
Output is correct |
5 |
Correct |
15 ms |
4188 KB |
Output is correct |
6 |
Correct |
10 ms |
3676 KB |
Output is correct |
7 |
Correct |
3 ms |
2648 KB |
Output is correct |
8 |
Correct |
10 ms |
3676 KB |
Output is correct |
9 |
Correct |
28 ms |
5516 KB |
Output is correct |
10 |
Correct |
15 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
7 ms |
3164 KB |
Output is correct |
17 |
Correct |
19 ms |
4668 KB |
Output is correct |
18 |
Correct |
26 ms |
4956 KB |
Output is correct |
19 |
Correct |
51 ms |
4700 KB |
Output is correct |
20 |
Correct |
56 ms |
4956 KB |
Output is correct |
21 |
Correct |
17 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
13 ms |
3676 KB |
Output is correct |
24 |
Correct |
27 ms |
4696 KB |
Output is correct |
25 |
Correct |
3 ms |
2652 KB |
Output is correct |
26 |
Correct |
16 ms |
4000 KB |
Output is correct |
27 |
Correct |
19 ms |
4264 KB |
Output is correct |
28 |
Correct |
23 ms |
4948 KB |
Output is correct |
29 |
Correct |
8 ms |
3424 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
4444 KB |
Output is correct |
2 |
Correct |
6 ms |
3032 KB |
Output is correct |
3 |
Correct |
12 ms |
3932 KB |
Output is correct |
4 |
Correct |
12 ms |
3676 KB |
Output is correct |
5 |
Correct |
15 ms |
4188 KB |
Output is correct |
6 |
Correct |
10 ms |
3676 KB |
Output is correct |
7 |
Correct |
3 ms |
2648 KB |
Output is correct |
8 |
Correct |
10 ms |
3676 KB |
Output is correct |
9 |
Correct |
28 ms |
5516 KB |
Output is correct |
10 |
Correct |
15 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
7 ms |
3164 KB |
Output is correct |
27 |
Correct |
19 ms |
4668 KB |
Output is correct |
28 |
Correct |
26 ms |
4956 KB |
Output is correct |
29 |
Correct |
51 ms |
4700 KB |
Output is correct |
30 |
Correct |
56 ms |
4956 KB |
Output is correct |
31 |
Correct |
17 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
13 ms |
3676 KB |
Output is correct |
34 |
Correct |
27 ms |
4696 KB |
Output is correct |
35 |
Correct |
3 ms |
2652 KB |
Output is correct |
36 |
Correct |
16 ms |
4000 KB |
Output is correct |
37 |
Correct |
19 ms |
4264 KB |
Output is correct |
38 |
Correct |
23 ms |
4948 KB |
Output is correct |
39 |
Correct |
8 ms |
3424 KB |
Output is correct |
40 |
Correct |
1 ms |
2392 KB |
Output is correct |
41 |
Correct |
50 ms |
5208 KB |
Output is correct |
42 |
Correct |
32 ms |
5504 KB |
Output is correct |
43 |
Correct |
34 ms |
5200 KB |
Output is correct |
44 |
Correct |
27 ms |
5520 KB |
Output is correct |
45 |
Correct |
26 ms |
5720 KB |
Output is correct |
46 |
Correct |
54 ms |
5456 KB |
Output is correct |
47 |
Correct |
29 ms |
5316 KB |
Output is correct |
48 |
Correct |
31 ms |
5460 KB |
Output is correct |
49 |
Correct |
30 ms |
5212 KB |
Output is correct |
50 |
Correct |
192 ms |
5608 KB |
Output is correct |
51 |
Correct |
207 ms |
5848 KB |
Output is correct |
52 |
Correct |
194 ms |
5700 KB |
Output is correct |
53 |
Correct |
203 ms |
5816 KB |
Output is correct |
54 |
Correct |
187 ms |
5536 KB |
Output is correct |
55 |
Correct |
209 ms |
5956 KB |
Output is correct |
56 |
Correct |
181 ms |
5200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
18 ms |
4444 KB |
Output is correct |
10 |
Correct |
6 ms |
3032 KB |
Output is correct |
11 |
Correct |
12 ms |
3932 KB |
Output is correct |
12 |
Correct |
12 ms |
3676 KB |
Output is correct |
13 |
Correct |
15 ms |
4188 KB |
Output is correct |
14 |
Correct |
10 ms |
3676 KB |
Output is correct |
15 |
Correct |
3 ms |
2648 KB |
Output is correct |
16 |
Correct |
10 ms |
3676 KB |
Output is correct |
17 |
Correct |
28 ms |
5516 KB |
Output is correct |
18 |
Correct |
15 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
7 ms |
3164 KB |
Output is correct |
35 |
Correct |
19 ms |
4668 KB |
Output is correct |
36 |
Correct |
26 ms |
4956 KB |
Output is correct |
37 |
Correct |
51 ms |
4700 KB |
Output is correct |
38 |
Correct |
56 ms |
4956 KB |
Output is correct |
39 |
Correct |
17 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
13 ms |
3676 KB |
Output is correct |
42 |
Correct |
27 ms |
4696 KB |
Output is correct |
43 |
Correct |
3 ms |
2652 KB |
Output is correct |
44 |
Correct |
16 ms |
4000 KB |
Output is correct |
45 |
Correct |
19 ms |
4264 KB |
Output is correct |
46 |
Correct |
23 ms |
4948 KB |
Output is correct |
47 |
Correct |
8 ms |
3424 KB |
Output is correct |
48 |
Correct |
1 ms |
2392 KB |
Output is correct |
49 |
Correct |
50 ms |
5208 KB |
Output is correct |
50 |
Correct |
32 ms |
5504 KB |
Output is correct |
51 |
Correct |
34 ms |
5200 KB |
Output is correct |
52 |
Correct |
27 ms |
5520 KB |
Output is correct |
53 |
Correct |
26 ms |
5720 KB |
Output is correct |
54 |
Correct |
54 ms |
5456 KB |
Output is correct |
55 |
Correct |
29 ms |
5316 KB |
Output is correct |
56 |
Correct |
31 ms |
5460 KB |
Output is correct |
57 |
Correct |
30 ms |
5212 KB |
Output is correct |
58 |
Correct |
192 ms |
5608 KB |
Output is correct |
59 |
Correct |
207 ms |
5848 KB |
Output is correct |
60 |
Correct |
194 ms |
5700 KB |
Output is correct |
61 |
Correct |
203 ms |
5816 KB |
Output is correct |
62 |
Correct |
187 ms |
5536 KB |
Output is correct |
63 |
Correct |
209 ms |
5956 KB |
Output is correct |
64 |
Correct |
181 ms |
5200 KB |
Output is correct |
65 |
Correct |
1 ms |
2512 KB |
Output is correct |
66 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |