// author lox:(
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define IZhO_SILVER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define popcnt __builtin_popcount
#define all(a) a.begin(),a.end()
#define low_b lower_bound
#define up_b upper_bound
#define vii vector<pair<ll,ll>>
#define vll vector<pair<ll,ll>>
#define pii pair<ll,ll>
#define mii map<ll,ll>
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vi vector<ll>
#define vl vector<ll>
#define pb push_back
#define endl '\n'
#define Y second
#define X first
typedef long double ld;
typedef long long ll;
const long long dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},col=107,N=1e6+777;
const ll mod=1e9+7,inf=1e18;
void fre_open(){freopen("file.in","r",stdin);freopen("file.out","w",stdout);}
ll binpow(ll n,ll k){if(k<0)return 0ll;if(k==0)return 1ll;if(k%2)return (binpow(n,k-1)*n)%mod;ll kk=binpow(n,k/2)%mod;return (kk*kk)%mod;}
ll n,k;
pll gg[N];
bool pr(ll x){//correct
for(ll i=2; i*i<=x; ++i){
if(x%i==0)return 0;
}
return 1;
}
void solve(){
cin>>n>>k;
if(k==0){//correct
ll x=n*n/2;
for(ll i=n/2; i>=1; --i)if(n%i==0)x=min(x,i*i*((n/i)*(n/i)/2));
cout<<x;
return;
}
if(pr(n)){//correct
ll x=n*n/2;
ll x2=x+1;
for(ll c=0, i1,i2,j1,j2;c<k; ++c){
cin>>i1>>j1>>i2>>j2;
for(ll i=i1; i<=i2; ++i)
for(ll j=j1; j<=j2; ++j)
{
if(i%2==j%2) x++,x2--;
if(i%2!=j%2) x2++,x--;
}
}
cout<<min(x,x2);
return;
}
if(n<=2e5){//?
for(ll i=1; i<=k; ++i){//correct
ll x,y,tox,toy;
cin>>x>>y>>tox>>toy;
gg[i]={x,y};
}
ll ans=inf-1;
for(ll d=1; d*d<n; ++d){
if(n%d!=0) continue;
ll m=n/d;
ll res1=0,res2=0;
for(ll i=1; i<=k; ++i){//correct, but not sure
ll x,y;
tie(x,y)=gg[i];
x=(x+(d-1))/d;
y=(y+(d-1))/d;
if((x+y)%2==0) res1++;
else res2++;
}
ans=min({ans,res1+((n/d)*(n/d))/2*d*d-res2,res2+((n/d)*(n/d)+1)/2*d*d-res1});
ll f=n/d;
m=n/f;
res1=0,res2=0;
for(ll i=1; i<=k; ++i){//correct, but not sure
ll x,y;
tie(x,y)=gg[i];
x=(x+(f-1))/f;
y=(y+(f-1))/f;
if((x+y)%2==0) res1++;
else res2++;
}
if(d==1){
ans=min(ans,max(res1+((n/f)*(n/f))/2*f*f-res2,res2+((n/f)*(n/f)+1)/2*f*f-res1));
continue;
}
ans=min({ans,res1+((n/f)*(n/f))/2*f*f-res2,res2+((n/f)*(n/f)+1)/2*f*f-res1});
}
cout<<ans<<endl;
return;
}
}
/*
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*/
int main() {
//fre_open();
IZhO_SILVER;
ll tt=1;
//cin>>tt;
while(tt--) solve();
}
Compilation message
chessboard.cpp: In function 'void solve()':
chessboard.cpp:69:16: warning: variable 'm' set but not used [-Wunused-but-set-variable]
69 | ll m=n/d;
| ^
chessboard.cpp: In function 'void fre_open()':
chessboard.cpp:27:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | void fre_open(){freopen("file.in","r",stdin);freopen("file.out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:27:53: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | void fre_open(){freopen("file.in","r",stdin);freopen("file.out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
280 KB |
Output is correct |
3 |
Correct |
15 ms |
320 KB |
Output is correct |
4 |
Correct |
14 ms |
320 KB |
Output is correct |
5 |
Correct |
17 ms |
316 KB |
Output is correct |
6 |
Correct |
13 ms |
324 KB |
Output is correct |
7 |
Correct |
4 ms |
204 KB |
Output is correct |
8 |
Correct |
10 ms |
216 KB |
Output is correct |
9 |
Correct |
31 ms |
204 KB |
Output is correct |
10 |
Correct |
18 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
8 ms |
716 KB |
Output is correct |
17 |
Correct |
18 ms |
204 KB |
Output is correct |
18 |
Correct |
28 ms |
1780 KB |
Output is correct |
19 |
Correct |
53 ms |
1588 KB |
Output is correct |
20 |
Correct |
63 ms |
1844 KB |
Output is correct |
21 |
Correct |
26 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
15 ms |
972 KB |
Output is correct |
24 |
Correct |
29 ms |
1668 KB |
Output is correct |
25 |
Correct |
3 ms |
332 KB |
Output is correct |
26 |
Correct |
16 ms |
1172 KB |
Output is correct |
27 |
Correct |
22 ms |
1356 KB |
Output is correct |
28 |
Correct |
27 ms |
1712 KB |
Output is correct |
29 |
Correct |
8 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
280 KB |
Output is correct |
3 |
Correct |
15 ms |
320 KB |
Output is correct |
4 |
Correct |
14 ms |
320 KB |
Output is correct |
5 |
Correct |
17 ms |
316 KB |
Output is correct |
6 |
Correct |
13 ms |
324 KB |
Output is correct |
7 |
Correct |
4 ms |
204 KB |
Output is correct |
8 |
Correct |
10 ms |
216 KB |
Output is correct |
9 |
Correct |
31 ms |
204 KB |
Output is correct |
10 |
Correct |
18 ms |
320 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
8 ms |
716 KB |
Output is correct |
27 |
Correct |
18 ms |
204 KB |
Output is correct |
28 |
Correct |
28 ms |
1780 KB |
Output is correct |
29 |
Correct |
53 ms |
1588 KB |
Output is correct |
30 |
Correct |
63 ms |
1844 KB |
Output is correct |
31 |
Correct |
26 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
15 ms |
972 KB |
Output is correct |
34 |
Correct |
29 ms |
1668 KB |
Output is correct |
35 |
Correct |
3 ms |
332 KB |
Output is correct |
36 |
Correct |
16 ms |
1172 KB |
Output is correct |
37 |
Correct |
22 ms |
1356 KB |
Output is correct |
38 |
Correct |
27 ms |
1712 KB |
Output is correct |
39 |
Correct |
8 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
50 ms |
1600 KB |
Output is correct |
42 |
Correct |
31 ms |
1732 KB |
Output is correct |
43 |
Correct |
50 ms |
1604 KB |
Output is correct |
44 |
Correct |
33 ms |
1728 KB |
Output is correct |
45 |
Correct |
26 ms |
332 KB |
Output is correct |
46 |
Correct |
58 ms |
1628 KB |
Output is correct |
47 |
Correct |
23 ms |
204 KB |
Output is correct |
48 |
Correct |
33 ms |
1616 KB |
Output is correct |
49 |
Correct |
29 ms |
1560 KB |
Output is correct |
50 |
Correct |
210 ms |
1720 KB |
Output is correct |
51 |
Correct |
212 ms |
1732 KB |
Output is correct |
52 |
Correct |
196 ms |
1708 KB |
Output is correct |
53 |
Correct |
213 ms |
1796 KB |
Output is correct |
54 |
Correct |
190 ms |
1636 KB |
Output is correct |
55 |
Correct |
228 ms |
1864 KB |
Output is correct |
56 |
Correct |
198 ms |
1648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
25 ms |
204 KB |
Output is correct |
10 |
Correct |
5 ms |
280 KB |
Output is correct |
11 |
Correct |
15 ms |
320 KB |
Output is correct |
12 |
Correct |
14 ms |
320 KB |
Output is correct |
13 |
Correct |
17 ms |
316 KB |
Output is correct |
14 |
Correct |
13 ms |
324 KB |
Output is correct |
15 |
Correct |
4 ms |
204 KB |
Output is correct |
16 |
Correct |
10 ms |
216 KB |
Output is correct |
17 |
Correct |
31 ms |
204 KB |
Output is correct |
18 |
Correct |
18 ms |
320 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
8 ms |
716 KB |
Output is correct |
35 |
Correct |
18 ms |
204 KB |
Output is correct |
36 |
Correct |
28 ms |
1780 KB |
Output is correct |
37 |
Correct |
53 ms |
1588 KB |
Output is correct |
38 |
Correct |
63 ms |
1844 KB |
Output is correct |
39 |
Correct |
26 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
15 ms |
972 KB |
Output is correct |
42 |
Correct |
29 ms |
1668 KB |
Output is correct |
43 |
Correct |
3 ms |
332 KB |
Output is correct |
44 |
Correct |
16 ms |
1172 KB |
Output is correct |
45 |
Correct |
22 ms |
1356 KB |
Output is correct |
46 |
Correct |
27 ms |
1712 KB |
Output is correct |
47 |
Correct |
8 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
50 ms |
1600 KB |
Output is correct |
50 |
Correct |
31 ms |
1732 KB |
Output is correct |
51 |
Correct |
50 ms |
1604 KB |
Output is correct |
52 |
Correct |
33 ms |
1728 KB |
Output is correct |
53 |
Correct |
26 ms |
332 KB |
Output is correct |
54 |
Correct |
58 ms |
1628 KB |
Output is correct |
55 |
Correct |
23 ms |
204 KB |
Output is correct |
56 |
Correct |
33 ms |
1616 KB |
Output is correct |
57 |
Correct |
29 ms |
1560 KB |
Output is correct |
58 |
Correct |
210 ms |
1720 KB |
Output is correct |
59 |
Correct |
212 ms |
1732 KB |
Output is correct |
60 |
Correct |
196 ms |
1708 KB |
Output is correct |
61 |
Correct |
213 ms |
1796 KB |
Output is correct |
62 |
Correct |
190 ms |
1636 KB |
Output is correct |
63 |
Correct |
228 ms |
1864 KB |
Output is correct |
64 |
Correct |
198 ms |
1648 KB |
Output is correct |
65 |
Correct |
0 ms |
204 KB |
Output is correct |
66 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |