#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
#define Y second
#define X first
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
const ll INF=1e18;
const int inf=1e9;
const int N=2e5+505;
const int M=3e3+10;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};
/*From Benq:
stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH*/
int n,k,used[3000][3000];
void solve(){
cin>>n>>k;
for(int i=1; i<=k; ++i){
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
used[x1][y1]++;
}vt<int>lst;
for(int i=1; i<=n; ++i)for(int j=1; j<=n; ++j)used[i][j]+=used[i][j-1]+used[i-1][j]-used[i-1][j-1];
for(int d=1; d*d<=n; ++d){
if(n%d==0){
lst.pb(d);
if(n/d!=d)lst.pb(n/d);
}
}int ans=inf;
for(int del:lst){
int cnt=0;
int ok=0;
int yes=0;
//cout<<del<<endl;
for(int i=1; i<=n; i+=del){
++ok;
int ok2=0;
for(int j=1; j<=n; j+=del){
++ok2;
if((ok+ok2)%2==0){
cnt+=(used[i+del-1][j+del-1]-used[i+del-1][j-1]-used[i-1][j+del-1]+used[i-1][j-1]);
continue;
}
//cout<<del<<' '<<i<<' '<<j<<' '<<(used[i+del-1][j+del-1]-used[i+del-1][j-1]-used[i-1][j+del-1]+used[i-1][j-1])<<endl;
yes=1;
cnt+=(del*del)-(used[i+del-1][j+del-1]-used[i+del-1][j-1]-used[i-1][j+del-1]+used[i-1][j-1]);
}
}int cnt2=0;
//cout<<endl
ok=0;
for(int i=1; i<=n; i+=del){
++ok;
int ok2=0;
for(int j=1; j<=n; j+=del){
++ok2;
if((ok+ok2)%2){
cnt2+=(used[i+del-1][j+del-1]-used[i+del-1][j-1]-used[i-1][j+del-1]+used[i-1][j-1]);
continue;
}
// cout<<i<<' '<<j<<endl;
cnt2+=(del*del)-(used[i+del-1][j+del-1]-used[i+del-1][j-1]-used[i-1][j+del-1]+used[i-1][j-1]);
}
}//cout<<cnt<<' '<<cnt2<<endl;
ans=min({ans,cnt2});
if(yes)ans=min(ans,cnt);
}cout<<ans<<endl;
}
int main(){
//srand(time(0));
//freopen("hotel.in","r",stdin);
//freopen("hotel.out","w",stdout);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tt=1,lolol=0;
// cin>>tt;
while(tt--) {
//cout<<"Case "<<++lolol<<": ";
solve();
}
}
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:89:11: warning: unused variable 'lolol' [-Wunused-variable]
89 | int tt=1,lolol=0;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
708 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
712 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
584 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
712 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
584 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
18 ms |
8020 KB |
Output is correct |
17 |
Correct |
35 ms |
9516 KB |
Output is correct |
18 |
Correct |
36 ms |
9680 KB |
Output is correct |
19 |
Correct |
33 ms |
9164 KB |
Output is correct |
20 |
Correct |
36 ms |
9328 KB |
Output is correct |
21 |
Correct |
32 ms |
9448 KB |
Output is correct |
22 |
Correct |
12 ms |
8248 KB |
Output is correct |
23 |
Correct |
25 ms |
8536 KB |
Output is correct |
24 |
Correct |
39 ms |
9620 KB |
Output is correct |
25 |
Correct |
11 ms |
8148 KB |
Output is correct |
26 |
Correct |
24 ms |
8524 KB |
Output is correct |
27 |
Correct |
29 ms |
8852 KB |
Output is correct |
28 |
Correct |
34 ms |
9164 KB |
Output is correct |
29 |
Correct |
17 ms |
8404 KB |
Output is correct |
30 |
Correct |
10 ms |
8068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
708 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |