#include<bits/stdc++.h>
#define ll long long
#define st string
#define fr first
#define se second
const long long mod=1e9+7;
using namespace std;
vector<pair<ll, ll> > v;
ll a[100100], b[100100], k, ans=1000000100;
void f(ll x)
{
for(ll i=1; i*i<=x; i++)
{
if(x%i==0)
{
v.push_back({i, x/i});
if(i>1) v.push_back({x/i, i});
}
}
}
void pro(ll p, ll o)
{
ll kb1=0, kb2=0;
for(ll i=1; i<=k; i++)
{
ll x=a[i], y=b[i];
x=(x+p-1)/p;
y=(y+p-1)/p;
if((x%2!=0 && y%2!=0) || (x%2==0 && y%2==0))
{
kb1++;
}
else kb2++;
}
//cout<<"kb1="<<kb1<<" kb2="<<kb2<<endl;
kb2=kb2+((o*o)/2+(o*o)%2)*p*p-(k-kb2);
kb1=kb1+((o*o)/2)*p*p-(k-kb1);
//cout<<"PPP= "<<kb1<<" "<<kb2<<" "<<p<<" "<<o<<'\n';
ans=min(kb1, min(ans, kb2));
}
main()
{
//freopen("1.txt", "r", stdin);
//freopen("1.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin>>n>>k;
if(!k)
{
cout<<(n*n)/2;
return 0;
}
f(n);
for(ll i=1; i<=k; i++)
cin>>a[i]>>b[i]>>a[i]>>b[i];
for(ll i=0; i<v.size(); i++)
{
pro(v[i].fr, v[i].se);
}
cout<<ans;
return 0;
}
/*
*/
Compilation message
chessboard.cpp:53:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
chessboard.cpp: In function 'int main()':
chessboard.cpp:74:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i=0; i<v.size(); i++)
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
2924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2924 KB |
Output is correct |
2 |
Correct |
2 ms |
2924 KB |
Output is correct |
3 |
Correct |
2 ms |
2924 KB |
Output is correct |
4 |
Correct |
3 ms |
2924 KB |
Output is correct |
5 |
Correct |
5 ms |
2924 KB |
Output is correct |
6 |
Correct |
2 ms |
2924 KB |
Output is correct |
7 |
Correct |
2 ms |
2924 KB |
Output is correct |
8 |
Correct |
2 ms |
2924 KB |
Output is correct |
9 |
Correct |
2 ms |
2924 KB |
Output is correct |
10 |
Correct |
2 ms |
2924 KB |
Output is correct |
11 |
Correct |
2 ms |
2924 KB |
Output is correct |
12 |
Correct |
2 ms |
2924 KB |
Output is correct |
13 |
Correct |
3 ms |
2924 KB |
Output is correct |
14 |
Correct |
3 ms |
2924 KB |
Output is correct |
15 |
Correct |
2 ms |
2924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2924 KB |
Output is correct |
2 |
Correct |
2 ms |
2924 KB |
Output is correct |
3 |
Correct |
2 ms |
2924 KB |
Output is correct |
4 |
Correct |
3 ms |
2924 KB |
Output is correct |
5 |
Correct |
5 ms |
2924 KB |
Output is correct |
6 |
Correct |
2 ms |
2924 KB |
Output is correct |
7 |
Correct |
2 ms |
2924 KB |
Output is correct |
8 |
Correct |
2 ms |
2924 KB |
Output is correct |
9 |
Correct |
2 ms |
2924 KB |
Output is correct |
10 |
Correct |
2 ms |
2924 KB |
Output is correct |
11 |
Correct |
2 ms |
2924 KB |
Output is correct |
12 |
Correct |
2 ms |
2924 KB |
Output is correct |
13 |
Correct |
3 ms |
2924 KB |
Output is correct |
14 |
Correct |
3 ms |
2924 KB |
Output is correct |
15 |
Correct |
2 ms |
2924 KB |
Output is correct |
16 |
Correct |
15 ms |
2924 KB |
Output is correct |
17 |
Correct |
33 ms |
3376 KB |
Output is correct |
18 |
Correct |
47 ms |
3632 KB |
Output is correct |
19 |
Correct |
127 ms |
3632 KB |
Output is correct |
20 |
Correct |
143 ms |
3632 KB |
Output is correct |
21 |
Correct |
33 ms |
3632 KB |
Output is correct |
22 |
Correct |
3 ms |
3632 KB |
Output is correct |
23 |
Correct |
28 ms |
3632 KB |
Output is correct |
24 |
Correct |
44 ms |
3632 KB |
Output is correct |
25 |
Correct |
8 ms |
3632 KB |
Output is correct |
26 |
Correct |
27 ms |
3632 KB |
Output is correct |
27 |
Correct |
38 ms |
3632 KB |
Output is correct |
28 |
Correct |
42 ms |
3632 KB |
Output is correct |
29 |
Correct |
14 ms |
3632 KB |
Output is correct |
30 |
Correct |
3 ms |
3632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
2924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |