답안 #99772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
99772 2019-03-07T02:57:18 Z choikiwon Chessboard (IZhO18_chessboard) C++17
100 / 100
764 ms 4412 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MN = 100010;

int N, K;
struct Rect {
    int r1, c1, r2, c2;
};
Rect rect[MN];

int main() {
    scanf("%d %d", &N, &K);

    for(int i = 0; i < K; i++) {
        scanf("%d %d %d %d", &rect[i].r1, &rect[i].c1, &rect[i].r2, &rect[i].c2);
        rect[i].r1--;
        rect[i].c1--;
        rect[i].r2--;
        rect[i].c2--;
    }

    ll mn = 1e18;
    for(int i = 1; i < N; i++) {
        if(N % i == 0) {
            for(int j = 0; j < 2; j++) {
                int n = N / i;

                ll tmp = j? (1LL * n * n + 1) / 2 : 1LL * n * n / 2;
                tmp *= 1LL * i * i;

                for(int k = 0; k < K; k++) {
                    int rr = min(rect[k].r2 + 1, (rect[k].r1 + i) / i * i);
                    int cc = min(rect[k].c2 + 1, (rect[k].c1 + i) / i * i);
                    int br = (rect[k].r2 - rr + 1) / (2 * i) * i;
                    int bc = (rect[k].c2 - cc + 1) / (2 * i) * i;
                    if((rect[k].r2 - rr + 1) % (2 * i) > i) br += (rect[k].r2 - rr + 1) % (2 * i) - i;
                    if((rect[k].c2 - cc + 1) % (2 * i) > i) bc += (rect[k].c2 - cc + 1) % (2 * i) - i;
                    br += rr - rect[k].r1;
                    bc += cc - rect[k].c1;
                    int wr = rect[k].r2 - rect[k].r1 + 1 - br;
                    int wc = rect[k].c2 - rect[k].c1 + 1 - bc;

                    if(j ^ ((rect[k].r1 / i + rect[k].c1 / i) & 1)) tmp -= 1LL * (br - wr) * (bc - wc);
                    else tmp += 1LL * (br - wr) * (bc - wc);
                }

                mn = min(mn, tmp);
            }
        }
    }
    printf("%lld", mn);
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:16: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:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %d", &rect[i].r1, &rect[i].c1, &rect[i].r2, &rect[i].c2);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1344 KB Output is correct
2 Correct 11 ms 640 KB Output is correct
3 Correct 23 ms 896 KB Output is correct
4 Correct 24 ms 1016 KB Output is correct
5 Correct 29 ms 1152 KB Output is correct
6 Correct 21 ms 896 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 30 ms 896 KB Output is correct
9 Correct 53 ms 1764 KB Output is correct
10 Correct 29 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 17 ms 896 KB Output is correct
17 Correct 39 ms 1660 KB Output is correct
18 Correct 75 ms 1896 KB Output is correct
19 Correct 166 ms 1652 KB Output is correct
20 Correct 165 ms 1884 KB Output is correct
21 Correct 41 ms 1656 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 38 ms 1124 KB Output is correct
24 Correct 52 ms 1912 KB Output is correct
25 Correct 8 ms 384 KB Output is correct
26 Correct 31 ms 1280 KB Output is correct
27 Correct 43 ms 1408 KB Output is correct
28 Correct 51 ms 1912 KB Output is correct
29 Correct 17 ms 896 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1344 KB Output is correct
2 Correct 11 ms 640 KB Output is correct
3 Correct 23 ms 896 KB Output is correct
4 Correct 24 ms 1016 KB Output is correct
5 Correct 29 ms 1152 KB Output is correct
6 Correct 21 ms 896 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 30 ms 896 KB Output is correct
9 Correct 53 ms 1764 KB Output is correct
10 Correct 29 ms 1152 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 3 ms 256 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 17 ms 896 KB Output is correct
27 Correct 39 ms 1660 KB Output is correct
28 Correct 75 ms 1896 KB Output is correct
29 Correct 166 ms 1652 KB Output is correct
30 Correct 165 ms 1884 KB Output is correct
31 Correct 41 ms 1656 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 38 ms 1124 KB Output is correct
34 Correct 52 ms 1912 KB Output is correct
35 Correct 8 ms 384 KB Output is correct
36 Correct 31 ms 1280 KB Output is correct
37 Correct 43 ms 1408 KB Output is correct
38 Correct 51 ms 1912 KB Output is correct
39 Correct 17 ms 896 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 141 ms 1540 KB Output is correct
42 Correct 67 ms 1912 KB Output is correct
43 Correct 83 ms 1784 KB Output is correct
44 Correct 67 ms 2040 KB Output is correct
45 Correct 52 ms 2168 KB Output is correct
46 Correct 145 ms 1912 KB Output is correct
47 Correct 45 ms 1784 KB Output is correct
48 Correct 68 ms 1784 KB Output is correct
49 Correct 52 ms 1792 KB Output is correct
50 Correct 671 ms 2040 KB Output is correct
51 Correct 764 ms 1912 KB Output is correct
52 Correct 591 ms 2040 KB Output is correct
53 Correct 657 ms 1912 KB Output is correct
54 Correct 650 ms 1868 KB Output is correct
55 Correct 649 ms 2116 KB Output is correct
56 Correct 619 ms 1788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 36 ms 1344 KB Output is correct
10 Correct 11 ms 640 KB Output is correct
11 Correct 23 ms 896 KB Output is correct
12 Correct 24 ms 1016 KB Output is correct
13 Correct 29 ms 1152 KB Output is correct
14 Correct 21 ms 896 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 30 ms 896 KB Output is correct
17 Correct 53 ms 1764 KB Output is correct
18 Correct 29 ms 1152 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 3 ms 256 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 17 ms 896 KB Output is correct
35 Correct 39 ms 1660 KB Output is correct
36 Correct 75 ms 1896 KB Output is correct
37 Correct 166 ms 1652 KB Output is correct
38 Correct 165 ms 1884 KB Output is correct
39 Correct 41 ms 1656 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 38 ms 1124 KB Output is correct
42 Correct 52 ms 1912 KB Output is correct
43 Correct 8 ms 384 KB Output is correct
44 Correct 31 ms 1280 KB Output is correct
45 Correct 43 ms 1408 KB Output is correct
46 Correct 51 ms 1912 KB Output is correct
47 Correct 17 ms 896 KB Output is correct
48 Correct 4 ms 384 KB Output is correct
49 Correct 141 ms 1540 KB Output is correct
50 Correct 67 ms 1912 KB Output is correct
51 Correct 83 ms 1784 KB Output is correct
52 Correct 67 ms 2040 KB Output is correct
53 Correct 52 ms 2168 KB Output is correct
54 Correct 145 ms 1912 KB Output is correct
55 Correct 45 ms 1784 KB Output is correct
56 Correct 68 ms 1784 KB Output is correct
57 Correct 52 ms 1792 KB Output is correct
58 Correct 671 ms 2040 KB Output is correct
59 Correct 764 ms 1912 KB Output is correct
60 Correct 591 ms 2040 KB Output is correct
61 Correct 657 ms 1912 KB Output is correct
62 Correct 650 ms 1868 KB Output is correct
63 Correct 649 ms 2116 KB Output is correct
64 Correct 619 ms 1788 KB Output is correct
65 Correct 3 ms 384 KB Output is correct
66 Correct 2 ms 432 KB Output is correct
67 Correct 634 ms 2012 KB Output is correct
68 Correct 685 ms 4092 KB Output is correct
69 Correct 598 ms 3704 KB Output is correct
70 Correct 661 ms 4088 KB Output is correct
71 Correct 638 ms 3988 KB Output is correct
72 Correct 618 ms 3832 KB Output is correct
73 Correct 571 ms 3804 KB Output is correct
74 Correct 590 ms 3960 KB Output is correct
75 Correct 561 ms 3832 KB Output is correct
76 Correct 586 ms 4088 KB Output is correct
77 Correct 122 ms 4216 KB Output is correct
78 Correct 64 ms 3832 KB Output is correct
79 Correct 95 ms 3712 KB Output is correct
80 Correct 104 ms 3960 KB Output is correct
81 Correct 94 ms 3572 KB Output is correct
82 Correct 80 ms 4088 KB Output is correct
83 Correct 72 ms 3812 KB Output is correct
84 Correct 421 ms 4216 KB Output is correct
85 Correct 700 ms 4348 KB Output is correct
86 Correct 4 ms 384 KB Output is correct
87 Correct 3 ms 384 KB Output is correct
88 Correct 695 ms 4412 KB Output is correct
89 Correct 135 ms 1156 KB Output is correct
90 Correct 3 ms 384 KB Output is correct