Submission #378743

# Submission time Handle Problem Language Result Execution time Memory
378743 2021-03-17T03:40:23 Z daniel920712 Chessboard (IZhO18_chessboard) C++14
100 / 100
864 ms 11172 KB
#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

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);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 4 ms 4972 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 3 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 8300 KB Output is correct
2 Correct 14 ms 5868 KB Output is correct
3 Correct 34 ms 7276 KB Output is correct
4 Correct 27 ms 7404 KB Output is correct
5 Correct 44 ms 7916 KB Output is correct
6 Correct 26 ms 6892 KB Output is correct
7 Correct 9 ms 5484 KB Output is correct
8 Correct 32 ms 7276 KB Output is correct
9 Correct 63 ms 9580 KB Output is correct
10 Correct 35 ms 7660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 5 ms 4972 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 4972 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 5 ms 4972 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 4972 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 17 ms 6380 KB Output is correct
17 Correct 40 ms 9436 KB Output is correct
18 Correct 51 ms 9452 KB Output is correct
19 Correct 109 ms 9324 KB Output is correct
20 Correct 118 ms 9324 KB Output is correct
21 Correct 39 ms 9324 KB Output is correct
22 Correct 4 ms 5100 KB Output is correct
23 Correct 29 ms 7096 KB Output is correct
24 Correct 47 ms 9452 KB Output is correct
25 Correct 9 ms 5484 KB Output is correct
26 Correct 31 ms 7660 KB Output is correct
27 Correct 41 ms 8812 KB Output is correct
28 Correct 49 ms 9324 KB Output is correct
29 Correct 19 ms 6764 KB Output is correct
30 Correct 6 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 8300 KB Output is correct
2 Correct 14 ms 5868 KB Output is correct
3 Correct 34 ms 7276 KB Output is correct
4 Correct 27 ms 7404 KB Output is correct
5 Correct 44 ms 7916 KB Output is correct
6 Correct 26 ms 6892 KB Output is correct
7 Correct 9 ms 5484 KB Output is correct
8 Correct 32 ms 7276 KB Output is correct
9 Correct 63 ms 9580 KB Output is correct
10 Correct 35 ms 7660 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 5 ms 4972 KB Output is correct
13 Correct 4 ms 4972 KB Output is correct
14 Correct 4 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 4972 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 4 ms 4972 KB Output is correct
20 Correct 4 ms 4972 KB Output is correct
21 Correct 4 ms 5100 KB Output is correct
22 Correct 4 ms 5100 KB Output is correct
23 Correct 4 ms 5100 KB Output is correct
24 Correct 4 ms 5100 KB Output is correct
25 Correct 4 ms 5100 KB Output is correct
26 Correct 17 ms 6380 KB Output is correct
27 Correct 40 ms 9436 KB Output is correct
28 Correct 51 ms 9452 KB Output is correct
29 Correct 109 ms 9324 KB Output is correct
30 Correct 118 ms 9324 KB Output is correct
31 Correct 39 ms 9324 KB Output is correct
32 Correct 4 ms 5100 KB Output is correct
33 Correct 29 ms 7096 KB Output is correct
34 Correct 47 ms 9452 KB Output is correct
35 Correct 9 ms 5484 KB Output is correct
36 Correct 31 ms 7660 KB Output is correct
37 Correct 41 ms 8812 KB Output is correct
38 Correct 49 ms 9324 KB Output is correct
39 Correct 19 ms 6764 KB Output is correct
40 Correct 6 ms 5100 KB Output is correct
41 Correct 194 ms 9564 KB Output is correct
42 Correct 98 ms 10244 KB Output is correct
43 Correct 123 ms 9580 KB Output is correct
44 Correct 92 ms 9964 KB Output is correct
45 Correct 88 ms 10220 KB Output is correct
46 Correct 199 ms 10092 KB Output is correct
47 Correct 72 ms 9836 KB Output is correct
48 Correct 114 ms 9708 KB Output is correct
49 Correct 84 ms 9580 KB Output is correct
50 Correct 704 ms 9832 KB Output is correct
51 Correct 751 ms 10240 KB Output is correct
52 Correct 702 ms 9836 KB Output is correct
53 Correct 795 ms 10328 KB Output is correct
54 Correct 732 ms 9836 KB Output is correct
55 Correct 827 ms 10220 KB Output is correct
56 Correct 653 ms 9644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 4 ms 4972 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 3 ms 4972 KB Output is correct
9 Correct 48 ms 8300 KB Output is correct
10 Correct 14 ms 5868 KB Output is correct
11 Correct 34 ms 7276 KB Output is correct
12 Correct 27 ms 7404 KB Output is correct
13 Correct 44 ms 7916 KB Output is correct
14 Correct 26 ms 6892 KB Output is correct
15 Correct 9 ms 5484 KB Output is correct
16 Correct 32 ms 7276 KB Output is correct
17 Correct 63 ms 9580 KB Output is correct
18 Correct 35 ms 7660 KB Output is correct
19 Correct 4 ms 4972 KB Output is correct
20 Correct 5 ms 4972 KB Output is correct
21 Correct 4 ms 4972 KB Output is correct
22 Correct 4 ms 5100 KB Output is correct
23 Correct 4 ms 5100 KB Output is correct
24 Correct 4 ms 4972 KB Output is correct
25 Correct 4 ms 5100 KB Output is correct
26 Correct 4 ms 5100 KB Output is correct
27 Correct 4 ms 4972 KB Output is correct
28 Correct 4 ms 4972 KB Output is correct
29 Correct 4 ms 5100 KB Output is correct
30 Correct 4 ms 5100 KB Output is correct
31 Correct 4 ms 5100 KB Output is correct
32 Correct 4 ms 5100 KB Output is correct
33 Correct 4 ms 5100 KB Output is correct
34 Correct 17 ms 6380 KB Output is correct
35 Correct 40 ms 9436 KB Output is correct
36 Correct 51 ms 9452 KB Output is correct
37 Correct 109 ms 9324 KB Output is correct
38 Correct 118 ms 9324 KB Output is correct
39 Correct 39 ms 9324 KB Output is correct
40 Correct 4 ms 5100 KB Output is correct
41 Correct 29 ms 7096 KB Output is correct
42 Correct 47 ms 9452 KB Output is correct
43 Correct 9 ms 5484 KB Output is correct
44 Correct 31 ms 7660 KB Output is correct
45 Correct 41 ms 8812 KB Output is correct
46 Correct 49 ms 9324 KB Output is correct
47 Correct 19 ms 6764 KB Output is correct
48 Correct 6 ms 5100 KB Output is correct
49 Correct 194 ms 9564 KB Output is correct
50 Correct 98 ms 10244 KB Output is correct
51 Correct 123 ms 9580 KB Output is correct
52 Correct 92 ms 9964 KB Output is correct
53 Correct 88 ms 10220 KB Output is correct
54 Correct 199 ms 10092 KB Output is correct
55 Correct 72 ms 9836 KB Output is correct
56 Correct 114 ms 9708 KB Output is correct
57 Correct 84 ms 9580 KB Output is correct
58 Correct 704 ms 9832 KB Output is correct
59 Correct 751 ms 10240 KB Output is correct
60 Correct 702 ms 9836 KB Output is correct
61 Correct 795 ms 10328 KB Output is correct
62 Correct 732 ms 9836 KB Output is correct
63 Correct 827 ms 10220 KB Output is correct
64 Correct 653 ms 9644 KB Output is correct
65 Correct 4 ms 4992 KB Output is correct
66 Correct 4 ms 4972 KB Output is correct
67 Correct 854 ms 9836 KB Output is correct
68 Correct 854 ms 10988 KB Output is correct
69 Correct 680 ms 10360 KB Output is correct
70 Correct 623 ms 10708 KB Output is correct
71 Correct 658 ms 10624 KB Output is correct
72 Correct 698 ms 10604 KB Output is correct
73 Correct 684 ms 10604 KB Output is correct
74 Correct 732 ms 10732 KB Output is correct
75 Correct 677 ms 10612 KB Output is correct
76 Correct 864 ms 10988 KB Output is correct
77 Correct 171 ms 11116 KB Output is correct
78 Correct 90 ms 10860 KB Output is correct
79 Correct 137 ms 10532 KB Output is correct
80 Correct 121 ms 10604 KB Output is correct
81 Correct 126 ms 10476 KB Output is correct
82 Correct 113 ms 10988 KB Output is correct
83 Correct 123 ms 10476 KB Output is correct
84 Correct 481 ms 11116 KB Output is correct
85 Correct 791 ms 11108 KB Output is correct
86 Correct 77 ms 4972 KB Output is correct
87 Correct 80 ms 4972 KB Output is correct
88 Correct 819 ms 11172 KB Output is correct
89 Correct 200 ms 6508 KB Output is correct
90 Correct 74 ms 4972 KB Output is correct