Submission #91265

# Submission time Handle Problem Language Result Execution time Memory
91265 2018-12-26T19:10:34 Z Vardanyan Chessboard (IZhO18_chessboard) C++14
100 / 100
353 ms 48872 KB
#include<bits/stdc++.h>

using namespace std;
const int N = 1000*100+5;
long long tox_type[N];
long long pref_type1[N];
long long pref_type2[N];
int X1[N],X2[N],Y1[N],Y2[N];
long long syun_pref_type[N];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i = 1;i<=k;i++) scanf("%d%d%d%d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
    long long ans = 100000000000000005;
    for(int w = 1;w<=n/2;w++){
        if(n%w) continue;
        memset(tox_type,0,sizeof tox_type);
        memset(pref_type1,0,sizeof pref_type1);
        memset(pref_type2,0,sizeof pref_type2);
        memset(syun_pref_type,0,sizeof syun_pref_type);
        for(int j = 1;j<=n;j++){
            int x = (j-1)/w;
            if(x%2 == 0){
                    // sev
                tox_type[j] = 1;
                syun_pref_type[j] = syun_pref_type[j-1]+1;
            }
            else{
                // spitak
                tox_type[j] = 2;
                syun_pref_type[j] = syun_pref_type[j-1];
            }
        }
        for(int j = 1;j<=n;j++){
            int x = (j-1)/w;
            if(x%2 == 0){
                pref_type1[j] = pref_type1[j-1]+1;
                pref_type2[j] = pref_type2[j-1];
            }
            else{
                pref_type1[j] = pref_type1[j-1];
                pref_type2[j] = pref_type2[j-1]+1;
            }
        }
        long long need = 0;
        long long need2 = 0;
        for(int i = 1;i<=n;i++){
            if(tox_type[i] == 1) need+=pref_type1[n];
            else need+=pref_type2[n];
        }
        need2 = n;
        need2*=n;
        need2-=need;
        for(int i = 1;i<=k;i++){
            long long x1 = X1[i],y1 = Y1[i];
            long long x2 = X2[i],y2 = Y2[i];
            long long qan_tp1 = syun_pref_type[x2]-syun_pref_type[x1-1];
            long long qan_tp2 = (x2-x1+1)-qan_tp1;
            long long sev = (qan_tp1*(pref_type1[y2]-pref_type1[y1-1])+qan_tp2*(pref_type2[y2]-pref_type2[y1-1]));
            need-=sev;
            need+=((x2-x1+1)*(y2-y1+1)-sev);
            need2-=((x2-x1+1)*(y2-y1+1)-sev);
            need2+=sev;
        }
        ans = min(ans,min(need,need2));

    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
chessboard.cpp:14:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1;i<=k;i++) scanf("%d%d%d%d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 4 ms 3448 KB Output is correct
3 Correct 4 ms 3480 KB Output is correct
4 Correct 4 ms 3528 KB Output is correct
5 Correct 4 ms 3584 KB Output is correct
6 Correct 5 ms 3588 KB Output is correct
7 Correct 4 ms 3604 KB Output is correct
8 Correct 4 ms 3604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 4628 KB Output is correct
2 Correct 10 ms 4628 KB Output is correct
3 Correct 20 ms 5140 KB Output is correct
4 Correct 20 ms 6080 KB Output is correct
5 Correct 27 ms 7596 KB Output is correct
6 Correct 19 ms 8120 KB Output is correct
7 Correct 8 ms 8120 KB Output is correct
8 Correct 18 ms 9192 KB Output is correct
9 Correct 40 ms 12064 KB Output is correct
10 Correct 24 ms 12604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12604 KB Output is correct
2 Correct 5 ms 12604 KB Output is correct
3 Correct 5 ms 12604 KB Output is correct
4 Correct 5 ms 12604 KB Output is correct
5 Correct 5 ms 12604 KB Output is correct
6 Correct 5 ms 12604 KB Output is correct
7 Correct 5 ms 12604 KB Output is correct
8 Correct 5 ms 12604 KB Output is correct
9 Correct 5 ms 12604 KB Output is correct
10 Correct 4 ms 12604 KB Output is correct
11 Correct 5 ms 12604 KB Output is correct
12 Correct 4 ms 12604 KB Output is correct
13 Correct 5 ms 12604 KB Output is correct
14 Correct 5 ms 12604 KB Output is correct
15 Correct 5 ms 12604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12604 KB Output is correct
2 Correct 5 ms 12604 KB Output is correct
3 Correct 5 ms 12604 KB Output is correct
4 Correct 5 ms 12604 KB Output is correct
5 Correct 5 ms 12604 KB Output is correct
6 Correct 5 ms 12604 KB Output is correct
7 Correct 5 ms 12604 KB Output is correct
8 Correct 5 ms 12604 KB Output is correct
9 Correct 5 ms 12604 KB Output is correct
10 Correct 4 ms 12604 KB Output is correct
11 Correct 5 ms 12604 KB Output is correct
12 Correct 4 ms 12604 KB Output is correct
13 Correct 5 ms 12604 KB Output is correct
14 Correct 5 ms 12604 KB Output is correct
15 Correct 5 ms 12604 KB Output is correct
16 Correct 13 ms 12900 KB Output is correct
17 Correct 31 ms 15144 KB Output is correct
18 Correct 37 ms 16988 KB Output is correct
19 Correct 44 ms 18204 KB Output is correct
20 Correct 49 ms 18888 KB Output is correct
21 Correct 30 ms 18888 KB Output is correct
22 Correct 6 ms 18888 KB Output is correct
23 Correct 19 ms 18888 KB Output is correct
24 Correct 34 ms 19968 KB Output is correct
25 Correct 8 ms 19968 KB Output is correct
26 Correct 23 ms 20608 KB Output is correct
27 Correct 29 ms 21840 KB Output is correct
28 Correct 37 ms 23616 KB Output is correct
29 Correct 15 ms 23616 KB Output is correct
30 Correct 5 ms 23616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 4628 KB Output is correct
2 Correct 10 ms 4628 KB Output is correct
3 Correct 20 ms 5140 KB Output is correct
4 Correct 20 ms 6080 KB Output is correct
5 Correct 27 ms 7596 KB Output is correct
6 Correct 19 ms 8120 KB Output is correct
7 Correct 8 ms 8120 KB Output is correct
8 Correct 18 ms 9192 KB Output is correct
9 Correct 40 ms 12064 KB Output is correct
10 Correct 24 ms 12604 KB Output is correct
11 Correct 5 ms 12604 KB Output is correct
12 Correct 5 ms 12604 KB Output is correct
13 Correct 5 ms 12604 KB Output is correct
14 Correct 5 ms 12604 KB Output is correct
15 Correct 5 ms 12604 KB Output is correct
16 Correct 5 ms 12604 KB Output is correct
17 Correct 5 ms 12604 KB Output is correct
18 Correct 5 ms 12604 KB Output is correct
19 Correct 5 ms 12604 KB Output is correct
20 Correct 4 ms 12604 KB Output is correct
21 Correct 5 ms 12604 KB Output is correct
22 Correct 4 ms 12604 KB Output is correct
23 Correct 5 ms 12604 KB Output is correct
24 Correct 5 ms 12604 KB Output is correct
25 Correct 5 ms 12604 KB Output is correct
26 Correct 13 ms 12900 KB Output is correct
27 Correct 31 ms 15144 KB Output is correct
28 Correct 37 ms 16988 KB Output is correct
29 Correct 44 ms 18204 KB Output is correct
30 Correct 49 ms 18888 KB Output is correct
31 Correct 30 ms 18888 KB Output is correct
32 Correct 6 ms 18888 KB Output is correct
33 Correct 19 ms 18888 KB Output is correct
34 Correct 34 ms 19968 KB Output is correct
35 Correct 8 ms 19968 KB Output is correct
36 Correct 23 ms 20608 KB Output is correct
37 Correct 29 ms 21840 KB Output is correct
38 Correct 37 ms 23616 KB Output is correct
39 Correct 15 ms 23616 KB Output is correct
40 Correct 5 ms 23616 KB Output is correct
41 Correct 78 ms 23616 KB Output is correct
42 Correct 49 ms 23632 KB Output is correct
43 Correct 57 ms 23632 KB Output is correct
44 Correct 47 ms 24588 KB Output is correct
45 Correct 46 ms 24744 KB Output is correct
46 Correct 83 ms 24752 KB Output is correct
47 Correct 40 ms 24752 KB Output is correct
48 Correct 51 ms 26784 KB Output is correct
49 Correct 45 ms 28688 KB Output is correct
50 Correct 248 ms 30936 KB Output is correct
51 Correct 249 ms 33376 KB Output is correct
52 Correct 252 ms 35448 KB Output is correct
53 Correct 353 ms 37828 KB Output is correct
54 Correct 246 ms 39840 KB Output is correct
55 Correct 260 ms 40300 KB Output is correct
56 Correct 243 ms 41700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 4 ms 3448 KB Output is correct
3 Correct 4 ms 3480 KB Output is correct
4 Correct 4 ms 3528 KB Output is correct
5 Correct 4 ms 3584 KB Output is correct
6 Correct 5 ms 3588 KB Output is correct
7 Correct 4 ms 3604 KB Output is correct
8 Correct 4 ms 3604 KB Output is correct
9 Correct 29 ms 4628 KB Output is correct
10 Correct 10 ms 4628 KB Output is correct
11 Correct 20 ms 5140 KB Output is correct
12 Correct 20 ms 6080 KB Output is correct
13 Correct 27 ms 7596 KB Output is correct
14 Correct 19 ms 8120 KB Output is correct
15 Correct 8 ms 8120 KB Output is correct
16 Correct 18 ms 9192 KB Output is correct
17 Correct 40 ms 12064 KB Output is correct
18 Correct 24 ms 12604 KB Output is correct
19 Correct 5 ms 12604 KB Output is correct
20 Correct 5 ms 12604 KB Output is correct
21 Correct 5 ms 12604 KB Output is correct
22 Correct 5 ms 12604 KB Output is correct
23 Correct 5 ms 12604 KB Output is correct
24 Correct 5 ms 12604 KB Output is correct
25 Correct 5 ms 12604 KB Output is correct
26 Correct 5 ms 12604 KB Output is correct
27 Correct 5 ms 12604 KB Output is correct
28 Correct 4 ms 12604 KB Output is correct
29 Correct 5 ms 12604 KB Output is correct
30 Correct 4 ms 12604 KB Output is correct
31 Correct 5 ms 12604 KB Output is correct
32 Correct 5 ms 12604 KB Output is correct
33 Correct 5 ms 12604 KB Output is correct
34 Correct 13 ms 12900 KB Output is correct
35 Correct 31 ms 15144 KB Output is correct
36 Correct 37 ms 16988 KB Output is correct
37 Correct 44 ms 18204 KB Output is correct
38 Correct 49 ms 18888 KB Output is correct
39 Correct 30 ms 18888 KB Output is correct
40 Correct 6 ms 18888 KB Output is correct
41 Correct 19 ms 18888 KB Output is correct
42 Correct 34 ms 19968 KB Output is correct
43 Correct 8 ms 19968 KB Output is correct
44 Correct 23 ms 20608 KB Output is correct
45 Correct 29 ms 21840 KB Output is correct
46 Correct 37 ms 23616 KB Output is correct
47 Correct 15 ms 23616 KB Output is correct
48 Correct 5 ms 23616 KB Output is correct
49 Correct 78 ms 23616 KB Output is correct
50 Correct 49 ms 23632 KB Output is correct
51 Correct 57 ms 23632 KB Output is correct
52 Correct 47 ms 24588 KB Output is correct
53 Correct 46 ms 24744 KB Output is correct
54 Correct 83 ms 24752 KB Output is correct
55 Correct 40 ms 24752 KB Output is correct
56 Correct 51 ms 26784 KB Output is correct
57 Correct 45 ms 28688 KB Output is correct
58 Correct 248 ms 30936 KB Output is correct
59 Correct 249 ms 33376 KB Output is correct
60 Correct 252 ms 35448 KB Output is correct
61 Correct 353 ms 37828 KB Output is correct
62 Correct 246 ms 39840 KB Output is correct
63 Correct 260 ms 40300 KB Output is correct
64 Correct 243 ms 41700 KB Output is correct
65 Correct 4 ms 41700 KB Output is correct
66 Correct 4 ms 41700 KB Output is correct
67 Correct 258 ms 41816 KB Output is correct
68 Correct 251 ms 41828 KB Output is correct
69 Correct 239 ms 41828 KB Output is correct
70 Correct 226 ms 41828 KB Output is correct
71 Correct 264 ms 41828 KB Output is correct
72 Correct 233 ms 41828 KB Output is correct
73 Correct 241 ms 41828 KB Output is correct
74 Correct 247 ms 44140 KB Output is correct
75 Correct 226 ms 46088 KB Output is correct
76 Correct 257 ms 48580 KB Output is correct
77 Correct 68 ms 48664 KB Output is correct
78 Correct 47 ms 48664 KB Output is correct
79 Correct 56 ms 48664 KB Output is correct
80 Correct 58 ms 48664 KB Output is correct
81 Correct 55 ms 48664 KB Output is correct
82 Correct 53 ms 48696 KB Output is correct
83 Correct 46 ms 48696 KB Output is correct
84 Correct 175 ms 48872 KB Output is correct
85 Correct 256 ms 48872 KB Output is correct
86 Correct 105 ms 48872 KB Output is correct
87 Correct 101 ms 48872 KB Output is correct
88 Correct 248 ms 48872 KB Output is correct
89 Correct 128 ms 48872 KB Output is correct
90 Correct 103 ms 48872 KB Output is correct