# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
378723 | daniel920712 | Chessboard (IZhO18_chessboard) | C++14 | 59 ms | 8816 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
vector < pair < int , int > > in[100005];
vector < pair < int , int > > out[100005];
vector < int > have;
int main()
{
long long N,M,ans=1e18,t,t2,a,b,c,d,i,j,k,x,y,m,n,l,r;
scanf("%lld %lld",&N,&M);
for(i=1;i<N;i++) if(N%i==0) have.push_back(i);
while(M--)
{
scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
in[a].push_back(make_pair(b,d));
out[c+1].push_back(make_pair(b,d));
}
for(auto i:have)
{
t=0;
t2=0;
a=0;
b=0;
c=0;
d=0;
a=N/i/2*i;
c=N/i/2*i;
if(N/i%2) c+=i;
for(j=1;j<=N;j++)
{
for(auto k:out[j])
{
l=(k.first-1)/i+1;
r=(k.second-1)/i-1;
x=y=(r-l+1)/2;
if((r-l+1)%2)
{
if(l%2==0) x++;
else y++;
}
d-=x*i;
c+=x*i;
b-=y*i;
a+=y*i;
if((k.first-1)/i==(k.second-1)/i)
{
if((k.first-1)/i%2)
{
b-=(k.second-k.first+1);
a+=(k.second-k.first+1);
}
else
{
d-=(k.second-k.first+1);
c+=(k.second-k.first+1);
}
}
else
{
if((k.first-1)/i%2)
{
b-=i-((k.first-1)%i);
a+=i-((k.first-1)%i);
}
else
{
d-=i-((k.first-1)%i);
c+=i-((k.first-1)%i);
}
if((k.second-1)/i%2)
{
b-=(k.second-1)%i+1;
a+=(k.second-1)%i+1;
}
else
{
d-=(k.second-1)%i+1;
c+=(k.second-1)%i+1;
}
}
}
for(auto k:in[j])
{
l=(k.first-1)/i+1;
r=(k.second-1)/i-1;
x=y=(r-l+1)/2;
if((r-l+1)%2)
{
if(l%2==0) x++;
else y++;
}
d+=x*i;
c-=x*i;
b+=y*i;
a-=y*i;
if((k.first-1)/i==(k.second-1)/i)
{
if((k.first-1)/i%2)
{
b+=(k.second-k.first+1);
a-=(k.second-k.first+1);
}
else
{
d+=(k.second-k.first+1);
c-=(k.second-k.first+1);
}
}
else
{
if((k.first-1)/i%2)
{
b+=i-((k.first-1)%i);
a-=i-((k.first-1)%i);
}
else
{
d+=i-((k.first-1)%i);
c-=i-((k.first-1)%i);
}
if((k.second-1)/i%2)
{
b+=(k.second-1)%i+1;
a-=(k.second-1)%i+1;
}
else
{
d+=(k.second-1)%i+1;
c-=(k.second-1)%i+1;
}
}
}
if((j-1)/i%2)
{
t+=a;
t+=d;
t2+=b;
t2+=c;
}
else
{
t2+=a;
t2+=d;
t+=b;
t+=c;
}
}
ans=min(ans,t);
ans=min(ans,t2);
}
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
*/
컴파일 시 표준 에러 (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... |