| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 378743 | daniel920712 | Chessboard (IZhO18_chessboard) | C++14 | 864 ms | 11172 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>
#include <set>
#include <algorithm>
using namespace std;
vector < pair < long long , long long > > in[100005];
vector < pair < long long , long long > > out[100005];
vector < long long > 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;
                if(r>=l)
                {
                    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;
                if(r>=l)
                {
                    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;
            }
            //printf("%lld %lld %lld %lld %lld %lld\n",i,j,a,b,c,d);
        }
        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
*/
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... | ||||
