답안 #378723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378723 2021-03-17T03:34:01 Z daniel920712 Chessboard (IZhO18_chessboard) C++14
8 / 100
59 ms 8816 KB
#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
*/

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:15:45: warning: unused variable 'k' [-Wunused-variable]
   15 |     long long N,M,ans=1e18,t,t2,a,b,c,d,i,j,k,x,y,m,n,l,r;
      |                                             ^
chessboard.cpp:15:51: warning: unused variable 'm' [-Wunused-variable]
   15 |     long long N,M,ans=1e18,t,t2,a,b,c,d,i,j,k,x,y,m,n,l,r;
      |                                                   ^
chessboard.cpp:15:53: warning: unused variable 'n' [-Wunused-variable]
   15 |     long long N,M,ans=1e18,t,t2,a,b,c,d,i,j,k,x,y,m,n,l,r;
      |                                                     ^
chessboard.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |     scanf("%lld %lld",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
chessboard.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |         scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 23 ms 4972 KB Output is correct
4 Correct 22 ms 4972 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 21 ms 4972 KB Output is correct
7 Correct 23 ms 4972 KB Output is correct
8 Correct 3 ms 4972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 8816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 4972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 4972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 8816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 23 ms 4972 KB Output is correct
4 Correct 22 ms 4972 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 21 ms 4972 KB Output is correct
7 Correct 23 ms 4972 KB Output is correct
8 Correct 3 ms 4972 KB Output is correct
9 Incorrect 59 ms 8816 KB Output isn't correct
10 Halted 0 ms 0 KB -