# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378540 | daniel920712 | Chessboard (IZhO18_chessboard) | C++14 | 66 ms | 8920 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
using namespace std;
vector < long long > have;
long long con1[100005];
long long con2[100005];
map < pair < long long , long long > , long long > con[100005];
int main()
{
long long N,M,ans=2e9,t,a,b,c,d,i,j,k,x,y;
scanf("%lld %lld",&N,&M);
for(i=1;i<N;i++)
{
if(N%i==0)
{
have.push_back(i);
con1[i]=(N/i)*(N/i)/2;
con2[i]=(N/i)*(N/i)/2+(N/i)*(N/i)%2;
//printf("%lld %lld %lld\n",i,con1[i],con2[i]);
}
}
while(M--)
{
scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
for(i=a;i<=c;i++)
{
for(j=b;j<=d;j++)
{
for(auto k:have)
{
x=(i-1)/k;
y=(j-1)/k;
if((x+y)%2)
{
if(con[k].find(make_pair(x,y))==con[k].end()) con1[k]--;
con[k][make_pair(x,y)]++;
}
else
{
if(con[k].find(make_pair(x,y))==con[k].end()) con2[k]--;
con[k][make_pair(x,y)]++;
}
}
}
}
}
for(auto i:have)
{
a=con1[i]*i*i;
for(auto j:con[i])
{
if((j.first.first+j.first.second)%2) a+=i*i-j.second;
else a+=j.second;
}
ans=min(ans,a);
a=con2[i]*i*i;
for(auto j:con[i])
{
if((j.first.first+j.first.second)%2==1) a+=i*i-j.second;
else a+=j.second;
}
ans=min(ans,a);
}
printf("%lld\n",ans);
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
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |