Submission #378557

# Submission time Handle Problem Language Result Execution time Memory
378557 2021-03-17T01:44:11 Z daniel920712 Chessboard (IZhO18_chessboard) C++14
47 / 100
2000 ms 161260 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <set>

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];
set < pair < long long , long long > > vis;
int main()
{
    long long N,M,ans=1e18,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++)
            {
                if(vis.find(make_pair(i,j))!=vis.end()) continue;
                vis.insert(make_pair(i,j));
                for(auto k:have)
                {
                    x=(i-1)/k;
                    y=(j-1)/k;
                    //printf("%lld %lld %lld %lld %lld\n",i,j,k,x,y);
                    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==0) 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

chessboard.cpp: In function 'int main()':
chessboard.cpp:16:28: warning: unused variable 't' [-Wunused-variable]
   16 |     long long N,M,ans=1e18,t,a,b,c,d,i,j,k,x,y;
      |                            ^
chessboard.cpp:16:42: warning: unused variable 'k' [-Wunused-variable]
   16 |     long long N,M,ans=1e18,t,a,b,c,d,i,j,k,x,y;
      |                                          ^
chessboard.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |     scanf("%lld %lld",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
chessboard.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |         scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB Output is correct
2 Correct 3 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 3 ms 4972 KB Output is correct
6 Correct 3 ms 4972 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 3 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 12908 KB Output is correct
2 Correct 25 ms 7148 KB Output is correct
3 Correct 62 ms 9964 KB Output is correct
4 Correct 78 ms 11116 KB Output is correct
5 Correct 96 ms 12396 KB Output is correct
6 Correct 54 ms 9708 KB Output is correct
7 Correct 13 ms 6124 KB Output is correct
8 Correct 55 ms 9708 KB Output is correct
9 Correct 181 ms 17260 KB Output is correct
10 Correct 84 ms 11884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Correct 5 ms 5100 KB Output is correct
4 Correct 6 ms 5228 KB Output is correct
5 Correct 6 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 5 ms 5228 KB Output is correct
8 Correct 5 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 3 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 5 ms 5228 KB Output is correct
14 Correct 5 ms 5228 KB Output is correct
15 Correct 5 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Correct 5 ms 5100 KB Output is correct
4 Correct 6 ms 5228 KB Output is correct
5 Correct 6 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 5 ms 5228 KB Output is correct
8 Correct 5 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 3 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 5 ms 5228 KB Output is correct
14 Correct 5 ms 5228 KB Output is correct
15 Correct 5 ms 5228 KB Output is correct
16 Correct 66 ms 9964 KB Output is correct
17 Correct 177 ms 15596 KB Output is correct
18 Correct 291 ms 19820 KB Output is correct
19 Correct 1071 ms 34284 KB Output is correct
20 Correct 1216 ms 36476 KB Output is correct
21 Correct 155 ms 15212 KB Output is correct
22 Correct 6 ms 5356 KB Output is correct
23 Correct 177 ms 14956 KB Output is correct
24 Correct 265 ms 18616 KB Output is correct
25 Correct 29 ms 7020 KB Output is correct
26 Correct 152 ms 13932 KB Output is correct
27 Correct 275 ms 19948 KB Output is correct
28 Correct 312 ms 22252 KB Output is correct
29 Correct 50 ms 9196 KB Output is correct
30 Correct 8 ms 5484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 12908 KB Output is correct
2 Correct 25 ms 7148 KB Output is correct
3 Correct 62 ms 9964 KB Output is correct
4 Correct 78 ms 11116 KB Output is correct
5 Correct 96 ms 12396 KB Output is correct
6 Correct 54 ms 9708 KB Output is correct
7 Correct 13 ms 6124 KB Output is correct
8 Correct 55 ms 9708 KB Output is correct
9 Correct 181 ms 17260 KB Output is correct
10 Correct 84 ms 11884 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 3 ms 4972 KB Output is correct
13 Correct 5 ms 5100 KB Output is correct
14 Correct 6 ms 5228 KB Output is correct
15 Correct 6 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 5 ms 5228 KB Output is correct
18 Correct 5 ms 5100 KB Output is correct
19 Correct 4 ms 5100 KB Output is correct
20 Correct 3 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 5 ms 5228 KB Output is correct
24 Correct 5 ms 5228 KB Output is correct
25 Correct 5 ms 5228 KB Output is correct
26 Correct 66 ms 9964 KB Output is correct
27 Correct 177 ms 15596 KB Output is correct
28 Correct 291 ms 19820 KB Output is correct
29 Correct 1071 ms 34284 KB Output is correct
30 Correct 1216 ms 36476 KB Output is correct
31 Correct 155 ms 15212 KB Output is correct
32 Correct 6 ms 5356 KB Output is correct
33 Correct 177 ms 14956 KB Output is correct
34 Correct 265 ms 18616 KB Output is correct
35 Correct 29 ms 7020 KB Output is correct
36 Correct 152 ms 13932 KB Output is correct
37 Correct 275 ms 19948 KB Output is correct
38 Correct 312 ms 22252 KB Output is correct
39 Correct 50 ms 9196 KB Output is correct
40 Correct 8 ms 5484 KB Output is correct
41 Correct 1593 ms 77548 KB Output is correct
42 Correct 332 ms 23404 KB Output is correct
43 Correct 747 ms 42772 KB Output is correct
44 Correct 286 ms 22960 KB Output is correct
45 Correct 192 ms 18028 KB Output is correct
46 Correct 1866 ms 85092 KB Output is correct
47 Correct 167 ms 16620 KB Output is correct
48 Correct 568 ms 33900 KB Output is correct
49 Correct 285 ms 21612 KB Output is correct
50 Execution timed out 2085 ms 161260 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB Output is correct
2 Correct 3 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 3 ms 4972 KB Output is correct
6 Correct 3 ms 4972 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 3 ms 4972 KB Output is correct
9 Correct 116 ms 12908 KB Output is correct
10 Correct 25 ms 7148 KB Output is correct
11 Correct 62 ms 9964 KB Output is correct
12 Correct 78 ms 11116 KB Output is correct
13 Correct 96 ms 12396 KB Output is correct
14 Correct 54 ms 9708 KB Output is correct
15 Correct 13 ms 6124 KB Output is correct
16 Correct 55 ms 9708 KB Output is correct
17 Correct 181 ms 17260 KB Output is correct
18 Correct 84 ms 11884 KB Output is correct
19 Correct 4 ms 5100 KB Output is correct
20 Correct 3 ms 4972 KB Output is correct
21 Correct 5 ms 5100 KB Output is correct
22 Correct 6 ms 5228 KB Output is correct
23 Correct 6 ms 5100 KB Output is correct
24 Correct 4 ms 5100 KB Output is correct
25 Correct 5 ms 5228 KB Output is correct
26 Correct 5 ms 5100 KB Output is correct
27 Correct 4 ms 5100 KB Output is correct
28 Correct 3 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 5 ms 5228 KB Output is correct
32 Correct 5 ms 5228 KB Output is correct
33 Correct 5 ms 5228 KB Output is correct
34 Correct 66 ms 9964 KB Output is correct
35 Correct 177 ms 15596 KB Output is correct
36 Correct 291 ms 19820 KB Output is correct
37 Correct 1071 ms 34284 KB Output is correct
38 Correct 1216 ms 36476 KB Output is correct
39 Correct 155 ms 15212 KB Output is correct
40 Correct 6 ms 5356 KB Output is correct
41 Correct 177 ms 14956 KB Output is correct
42 Correct 265 ms 18616 KB Output is correct
43 Correct 29 ms 7020 KB Output is correct
44 Correct 152 ms 13932 KB Output is correct
45 Correct 275 ms 19948 KB Output is correct
46 Correct 312 ms 22252 KB Output is correct
47 Correct 50 ms 9196 KB Output is correct
48 Correct 8 ms 5484 KB Output is correct
49 Correct 1593 ms 77548 KB Output is correct
50 Correct 332 ms 23404 KB Output is correct
51 Correct 747 ms 42772 KB Output is correct
52 Correct 286 ms 22960 KB Output is correct
53 Correct 192 ms 18028 KB Output is correct
54 Correct 1866 ms 85092 KB Output is correct
55 Correct 167 ms 16620 KB Output is correct
56 Correct 568 ms 33900 KB Output is correct
57 Correct 285 ms 21612 KB Output is correct
58 Execution timed out 2085 ms 161260 KB Time limit exceeded
59 Halted 0 ms 0 KB -