//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x << " = " << x << endl;
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;
const ll N = 1e6+5 , M = 2e3+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
using namespace std;
int n;
bool u[N];
int dp[M][M];
ll check(int k){
int cnt0 = 0 , cnt1 = 0;
int cnt10 = 0 , cnt11 = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if((i/k)%2==(j/k)%2) {
if(dp[i][j] == 1) cnt1++;
else cnt0++;
} else {
if(dp[i][j] == 1) cnt11++;
else cnt10++;
}
}
}
return min(cnt0+cnt11 , cnt10+cnt1);
}
void solve(){
ll k;
cin >> n >> k;
if(u[n] == 0){
ll cnt = 0 , cnt1 = 0;
for(int i = 1; i <= k; i++){
ll x , y , x1 , y1;
cin >> x >> y >> x1 >> y1;
if(x % 2 == y % 2) cnt++;
else cnt1++;
}
cout << min((n*n+1)/2-cnt+cnt1 , n*n/2-cnt1+cnt) <<"\n";
return;
} else {
for(int i = 1; i <= k; i++){
ll x , y , x1 , y1;
cin >> x >> y >> x1 >> y1;
x--;
y--;
dp[x][y] = 1;
}
ll mn = INF;
for(int i = 1; i <= sqrtl(n); i++){
if(n % i == 0){
mn = min(mn , check(i));
if(i > 1) mn = min(mn , check(n/i));
}
}
cout << mn <<"\n";
}
}
signed main(){
ios;
u[1] = 1;
for(int i = 2; i <= N-5; i++){
if(u[i] == 1) continue;
for(ll j = i*i; j <= N-5; j+=i) u[j] = 1;
}
solve();
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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1236 KB |
Output is correct |
2 |
Correct |
4 ms |
1192 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
4 ms |
1236 KB |
Output is correct |
5 |
Correct |
3 ms |
1236 KB |
Output is correct |
6 |
Correct |
4 ms |
1236 KB |
Output is correct |
7 |
Correct |
3 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1308 KB |
Output is correct |
2 |
Correct |
8 ms |
1308 KB |
Output is correct |
3 |
Correct |
13 ms |
1236 KB |
Output is correct |
4 |
Correct |
17 ms |
1308 KB |
Output is correct |
5 |
Correct |
18 ms |
1236 KB |
Output is correct |
6 |
Correct |
13 ms |
1236 KB |
Output is correct |
7 |
Correct |
5 ms |
1236 KB |
Output is correct |
8 |
Correct |
12 ms |
1236 KB |
Output is correct |
9 |
Correct |
27 ms |
1236 KB |
Output is correct |
10 |
Correct |
22 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1620 KB |
Output is correct |
2 |
Correct |
3 ms |
1364 KB |
Output is correct |
3 |
Correct |
3 ms |
1492 KB |
Output is correct |
4 |
Correct |
4 ms |
1620 KB |
Output is correct |
5 |
Correct |
3 ms |
1612 KB |
Output is correct |
6 |
Correct |
4 ms |
1620 KB |
Output is correct |
7 |
Correct |
6 ms |
1748 KB |
Output is correct |
8 |
Correct |
4 ms |
1492 KB |
Output is correct |
9 |
Correct |
4 ms |
1620 KB |
Output is correct |
10 |
Correct |
4 ms |
1236 KB |
Output is correct |
11 |
Correct |
4 ms |
1492 KB |
Output is correct |
12 |
Correct |
3 ms |
1288 KB |
Output is correct |
13 |
Correct |
5 ms |
1492 KB |
Output is correct |
14 |
Correct |
4 ms |
1592 KB |
Output is correct |
15 |
Correct |
4 ms |
1444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1620 KB |
Output is correct |
2 |
Correct |
3 ms |
1364 KB |
Output is correct |
3 |
Correct |
3 ms |
1492 KB |
Output is correct |
4 |
Correct |
4 ms |
1620 KB |
Output is correct |
5 |
Correct |
3 ms |
1612 KB |
Output is correct |
6 |
Correct |
4 ms |
1620 KB |
Output is correct |
7 |
Correct |
6 ms |
1748 KB |
Output is correct |
8 |
Correct |
4 ms |
1492 KB |
Output is correct |
9 |
Correct |
4 ms |
1620 KB |
Output is correct |
10 |
Correct |
4 ms |
1236 KB |
Output is correct |
11 |
Correct |
4 ms |
1492 KB |
Output is correct |
12 |
Correct |
3 ms |
1288 KB |
Output is correct |
13 |
Correct |
5 ms |
1492 KB |
Output is correct |
14 |
Correct |
4 ms |
1592 KB |
Output is correct |
15 |
Correct |
4 ms |
1444 KB |
Output is correct |
16 |
Correct |
29 ms |
12076 KB |
Output is correct |
17 |
Correct |
27 ms |
2592 KB |
Output is correct |
18 |
Correct |
52 ms |
14428 KB |
Output is correct |
19 |
Correct |
167 ms |
13636 KB |
Output is correct |
20 |
Correct |
171 ms |
13792 KB |
Output is correct |
21 |
Correct |
21 ms |
2564 KB |
Output is correct |
22 |
Correct |
82 ms |
2900 KB |
Output is correct |
23 |
Correct |
54 ms |
12912 KB |
Output is correct |
24 |
Correct |
52 ms |
14340 KB |
Output is correct |
25 |
Correct |
44 ms |
10948 KB |
Output is correct |
26 |
Correct |
38 ms |
12840 KB |
Output is correct |
27 |
Correct |
53 ms |
13320 KB |
Output is correct |
28 |
Correct |
60 ms |
13720 KB |
Output is correct |
29 |
Correct |
11 ms |
1832 KB |
Output is correct |
30 |
Correct |
23 ms |
7832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1308 KB |
Output is correct |
2 |
Correct |
8 ms |
1308 KB |
Output is correct |
3 |
Correct |
13 ms |
1236 KB |
Output is correct |
4 |
Correct |
17 ms |
1308 KB |
Output is correct |
5 |
Correct |
18 ms |
1236 KB |
Output is correct |
6 |
Correct |
13 ms |
1236 KB |
Output is correct |
7 |
Correct |
5 ms |
1236 KB |
Output is correct |
8 |
Correct |
12 ms |
1236 KB |
Output is correct |
9 |
Correct |
27 ms |
1236 KB |
Output is correct |
10 |
Correct |
22 ms |
1364 KB |
Output is correct |
11 |
Correct |
4 ms |
1620 KB |
Output is correct |
12 |
Correct |
3 ms |
1364 KB |
Output is correct |
13 |
Correct |
3 ms |
1492 KB |
Output is correct |
14 |
Correct |
4 ms |
1620 KB |
Output is correct |
15 |
Correct |
3 ms |
1612 KB |
Output is correct |
16 |
Correct |
4 ms |
1620 KB |
Output is correct |
17 |
Correct |
6 ms |
1748 KB |
Output is correct |
18 |
Correct |
4 ms |
1492 KB |
Output is correct |
19 |
Correct |
4 ms |
1620 KB |
Output is correct |
20 |
Correct |
4 ms |
1236 KB |
Output is correct |
21 |
Correct |
4 ms |
1492 KB |
Output is correct |
22 |
Correct |
3 ms |
1288 KB |
Output is correct |
23 |
Correct |
5 ms |
1492 KB |
Output is correct |
24 |
Correct |
4 ms |
1592 KB |
Output is correct |
25 |
Correct |
4 ms |
1444 KB |
Output is correct |
26 |
Correct |
29 ms |
12076 KB |
Output is correct |
27 |
Correct |
27 ms |
2592 KB |
Output is correct |
28 |
Correct |
52 ms |
14428 KB |
Output is correct |
29 |
Correct |
167 ms |
13636 KB |
Output is correct |
30 |
Correct |
171 ms |
13792 KB |
Output is correct |
31 |
Correct |
21 ms |
2564 KB |
Output is correct |
32 |
Correct |
82 ms |
2900 KB |
Output is correct |
33 |
Correct |
54 ms |
12912 KB |
Output is correct |
34 |
Correct |
52 ms |
14340 KB |
Output is correct |
35 |
Correct |
44 ms |
10948 KB |
Output is correct |
36 |
Correct |
38 ms |
12840 KB |
Output is correct |
37 |
Correct |
53 ms |
13320 KB |
Output is correct |
38 |
Correct |
60 ms |
13720 KB |
Output is correct |
39 |
Correct |
11 ms |
1832 KB |
Output is correct |
40 |
Correct |
23 ms |
7832 KB |
Output is correct |
41 |
Runtime error |
5 ms |
2472 KB |
Execution killed with signal 11 |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1236 KB |
Output is correct |
2 |
Correct |
4 ms |
1192 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
4 ms |
1236 KB |
Output is correct |
5 |
Correct |
3 ms |
1236 KB |
Output is correct |
6 |
Correct |
4 ms |
1236 KB |
Output is correct |
7 |
Correct |
3 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1236 KB |
Output is correct |
9 |
Correct |
20 ms |
1308 KB |
Output is correct |
10 |
Correct |
8 ms |
1308 KB |
Output is correct |
11 |
Correct |
13 ms |
1236 KB |
Output is correct |
12 |
Correct |
17 ms |
1308 KB |
Output is correct |
13 |
Correct |
18 ms |
1236 KB |
Output is correct |
14 |
Correct |
13 ms |
1236 KB |
Output is correct |
15 |
Correct |
5 ms |
1236 KB |
Output is correct |
16 |
Correct |
12 ms |
1236 KB |
Output is correct |
17 |
Correct |
27 ms |
1236 KB |
Output is correct |
18 |
Correct |
22 ms |
1364 KB |
Output is correct |
19 |
Correct |
4 ms |
1620 KB |
Output is correct |
20 |
Correct |
3 ms |
1364 KB |
Output is correct |
21 |
Correct |
3 ms |
1492 KB |
Output is correct |
22 |
Correct |
4 ms |
1620 KB |
Output is correct |
23 |
Correct |
3 ms |
1612 KB |
Output is correct |
24 |
Correct |
4 ms |
1620 KB |
Output is correct |
25 |
Correct |
6 ms |
1748 KB |
Output is correct |
26 |
Correct |
4 ms |
1492 KB |
Output is correct |
27 |
Correct |
4 ms |
1620 KB |
Output is correct |
28 |
Correct |
4 ms |
1236 KB |
Output is correct |
29 |
Correct |
4 ms |
1492 KB |
Output is correct |
30 |
Correct |
3 ms |
1288 KB |
Output is correct |
31 |
Correct |
5 ms |
1492 KB |
Output is correct |
32 |
Correct |
4 ms |
1592 KB |
Output is correct |
33 |
Correct |
4 ms |
1444 KB |
Output is correct |
34 |
Correct |
29 ms |
12076 KB |
Output is correct |
35 |
Correct |
27 ms |
2592 KB |
Output is correct |
36 |
Correct |
52 ms |
14428 KB |
Output is correct |
37 |
Correct |
167 ms |
13636 KB |
Output is correct |
38 |
Correct |
171 ms |
13792 KB |
Output is correct |
39 |
Correct |
21 ms |
2564 KB |
Output is correct |
40 |
Correct |
82 ms |
2900 KB |
Output is correct |
41 |
Correct |
54 ms |
12912 KB |
Output is correct |
42 |
Correct |
52 ms |
14340 KB |
Output is correct |
43 |
Correct |
44 ms |
10948 KB |
Output is correct |
44 |
Correct |
38 ms |
12840 KB |
Output is correct |
45 |
Correct |
53 ms |
13320 KB |
Output is correct |
46 |
Correct |
60 ms |
13720 KB |
Output is correct |
47 |
Correct |
11 ms |
1832 KB |
Output is correct |
48 |
Correct |
23 ms |
7832 KB |
Output is correct |
49 |
Runtime error |
5 ms |
2472 KB |
Execution killed with signal 11 |
50 |
Halted |
0 ms |
0 KB |
- |