Submission #50842

# Submission time Handle Problem Language Result Execution time Memory
50842 2018-06-13T16:30:15 Z Nicksechko Chessboard (IZhO18_chessboard) C++14
100 / 100
715 ms 2300 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int MX = 100 * 1000 + 7;

#define y1 ak_a_kak_podnyat

int x1[MX], y1[MX], x2[MX], y2[MX];

pair<int, int> slv(int l, int r, int s) {
    if (l / s == r / s) {
        int b = l / s;
        if (b & 1) {
            return {0, r - l + 1};
        } else {
            return {r - l + 1, 0};
        }
    } else {
        pair<int, int> a(0, 0);
        int nl = l - l % s + s, nr = r - r % s - 1;
        if ((l / s) % 2 == 0) {
            a.first += nl - l;
        } else {
            a.second += nl - l;
        }
        if ((r / s) % 2 == 0) {
            a.first += r - nr;
        } else {
            a.second += r - nr;
        }
        int bl = (nr - nl + 1) / s;
        if (bl & 1) {
            if ((nl / s) % 2 == 0) {
                a.first += s;
            } else {
                a.second += s;
            }
            bl--;
        }
        a.first += (bl / 2) * s;
        a.second += (bl / 2) * s;
        return a;
    }
}

ll solve(int n, int m, int s) {
    ll g0 = 0, g1 = 0;
    for (int i = 0; i < m; i++) {
        auto p1 = slv(x1[i], x2[i], s);
        auto p2 = slv(y1[i], y2[i], s);
        g0 += 1LL * p1.first * p2.first;
        g0 += 1LL * p1.second * p2.second;
        g1 += 1LL * p1.second * p2.first;
        g1 += 1LL * p1.first * p2.second;
    }
    n /= s;
    ll b0 = (1LL * n * n + 1) / 2 * s * s;
    ll b1 = (1LL * n * n) / 2 * s * s;
    return min(g0 + b1 - g1, g1 + b0 - g0);
}

int main() {
#ifdef AZINO777
    freopen("in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d %d %d", &x1[i], &y1[i], &x2[i], &y2[i]);
        x1[i]--;
        y1[i]--;
        x2[i]--;
        y2[i]--;
    }
    ll ans = 2e18;
    for (int i = 1; i < n; i++) {
        if (n % i == 0) {
            ans = min(ans, solve(n, m, i));
        }
    }
    printf("%lld\n", ans);
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
chessboard.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %d", &x1[i], &y1[i], &x2[i], &y2[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 3 ms 552 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 3 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 1620 KB Output is correct
2 Correct 16 ms 1620 KB Output is correct
3 Correct 29 ms 1620 KB Output is correct
4 Correct 29 ms 1620 KB Output is correct
5 Correct 43 ms 1620 KB Output is correct
6 Correct 21 ms 1620 KB Output is correct
7 Correct 9 ms 1620 KB Output is correct
8 Correct 21 ms 1620 KB Output is correct
9 Correct 58 ms 2132 KB Output is correct
10 Correct 34 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2132 KB Output is correct
2 Correct 2 ms 2132 KB Output is correct
3 Correct 3 ms 2132 KB Output is correct
4 Correct 4 ms 2132 KB Output is correct
5 Correct 2 ms 2132 KB Output is correct
6 Correct 3 ms 2132 KB Output is correct
7 Correct 4 ms 2132 KB Output is correct
8 Correct 5 ms 2132 KB Output is correct
9 Correct 3 ms 2132 KB Output is correct
10 Correct 3 ms 2132 KB Output is correct
11 Correct 3 ms 2132 KB Output is correct
12 Correct 3 ms 2132 KB Output is correct
13 Correct 3 ms 2132 KB Output is correct
14 Correct 3 ms 2132 KB Output is correct
15 Correct 3 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2132 KB Output is correct
2 Correct 2 ms 2132 KB Output is correct
3 Correct 3 ms 2132 KB Output is correct
4 Correct 4 ms 2132 KB Output is correct
5 Correct 2 ms 2132 KB Output is correct
6 Correct 3 ms 2132 KB Output is correct
7 Correct 4 ms 2132 KB Output is correct
8 Correct 5 ms 2132 KB Output is correct
9 Correct 3 ms 2132 KB Output is correct
10 Correct 3 ms 2132 KB Output is correct
11 Correct 3 ms 2132 KB Output is correct
12 Correct 3 ms 2132 KB Output is correct
13 Correct 3 ms 2132 KB Output is correct
14 Correct 3 ms 2132 KB Output is correct
15 Correct 3 ms 2132 KB Output is correct
16 Correct 18 ms 2132 KB Output is correct
17 Correct 44 ms 2132 KB Output is correct
18 Correct 52 ms 2172 KB Output is correct
19 Correct 127 ms 2172 KB Output is correct
20 Correct 149 ms 2300 KB Output is correct
21 Correct 55 ms 2300 KB Output is correct
22 Correct 3 ms 2300 KB Output is correct
23 Correct 38 ms 2300 KB Output is correct
24 Correct 52 ms 2300 KB Output is correct
25 Correct 8 ms 2300 KB Output is correct
26 Correct 42 ms 2300 KB Output is correct
27 Correct 55 ms 2300 KB Output is correct
28 Correct 55 ms 2300 KB Output is correct
29 Correct 17 ms 2300 KB Output is correct
30 Correct 5 ms 2300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 1620 KB Output is correct
2 Correct 16 ms 1620 KB Output is correct
3 Correct 29 ms 1620 KB Output is correct
4 Correct 29 ms 1620 KB Output is correct
5 Correct 43 ms 1620 KB Output is correct
6 Correct 21 ms 1620 KB Output is correct
7 Correct 9 ms 1620 KB Output is correct
8 Correct 21 ms 1620 KB Output is correct
9 Correct 58 ms 2132 KB Output is correct
10 Correct 34 ms 2132 KB Output is correct
11 Correct 2 ms 2132 KB Output is correct
12 Correct 2 ms 2132 KB Output is correct
13 Correct 3 ms 2132 KB Output is correct
14 Correct 4 ms 2132 KB Output is correct
15 Correct 2 ms 2132 KB Output is correct
16 Correct 3 ms 2132 KB Output is correct
17 Correct 4 ms 2132 KB Output is correct
18 Correct 5 ms 2132 KB Output is correct
19 Correct 3 ms 2132 KB Output is correct
20 Correct 3 ms 2132 KB Output is correct
21 Correct 3 ms 2132 KB Output is correct
22 Correct 3 ms 2132 KB Output is correct
23 Correct 3 ms 2132 KB Output is correct
24 Correct 3 ms 2132 KB Output is correct
25 Correct 3 ms 2132 KB Output is correct
26 Correct 18 ms 2132 KB Output is correct
27 Correct 44 ms 2132 KB Output is correct
28 Correct 52 ms 2172 KB Output is correct
29 Correct 127 ms 2172 KB Output is correct
30 Correct 149 ms 2300 KB Output is correct
31 Correct 55 ms 2300 KB Output is correct
32 Correct 3 ms 2300 KB Output is correct
33 Correct 38 ms 2300 KB Output is correct
34 Correct 52 ms 2300 KB Output is correct
35 Correct 8 ms 2300 KB Output is correct
36 Correct 42 ms 2300 KB Output is correct
37 Correct 55 ms 2300 KB Output is correct
38 Correct 55 ms 2300 KB Output is correct
39 Correct 17 ms 2300 KB Output is correct
40 Correct 5 ms 2300 KB Output is correct
41 Correct 115 ms 2300 KB Output is correct
42 Correct 60 ms 2300 KB Output is correct
43 Correct 81 ms 2300 KB Output is correct
44 Correct 61 ms 2300 KB Output is correct
45 Correct 57 ms 2300 KB Output is correct
46 Correct 125 ms 2300 KB Output is correct
47 Correct 49 ms 2300 KB Output is correct
48 Correct 86 ms 2300 KB Output is correct
49 Correct 55 ms 2300 KB Output is correct
50 Correct 471 ms 2300 KB Output is correct
51 Correct 552 ms 2300 KB Output is correct
52 Correct 453 ms 2300 KB Output is correct
53 Correct 564 ms 2300 KB Output is correct
54 Correct 489 ms 2300 KB Output is correct
55 Correct 547 ms 2300 KB Output is correct
56 Correct 465 ms 2300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 3 ms 552 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 3 ms 644 KB Output is correct
9 Correct 47 ms 1620 KB Output is correct
10 Correct 16 ms 1620 KB Output is correct
11 Correct 29 ms 1620 KB Output is correct
12 Correct 29 ms 1620 KB Output is correct
13 Correct 43 ms 1620 KB Output is correct
14 Correct 21 ms 1620 KB Output is correct
15 Correct 9 ms 1620 KB Output is correct
16 Correct 21 ms 1620 KB Output is correct
17 Correct 58 ms 2132 KB Output is correct
18 Correct 34 ms 2132 KB Output is correct
19 Correct 2 ms 2132 KB Output is correct
20 Correct 2 ms 2132 KB Output is correct
21 Correct 3 ms 2132 KB Output is correct
22 Correct 4 ms 2132 KB Output is correct
23 Correct 2 ms 2132 KB Output is correct
24 Correct 3 ms 2132 KB Output is correct
25 Correct 4 ms 2132 KB Output is correct
26 Correct 5 ms 2132 KB Output is correct
27 Correct 3 ms 2132 KB Output is correct
28 Correct 3 ms 2132 KB Output is correct
29 Correct 3 ms 2132 KB Output is correct
30 Correct 3 ms 2132 KB Output is correct
31 Correct 3 ms 2132 KB Output is correct
32 Correct 3 ms 2132 KB Output is correct
33 Correct 3 ms 2132 KB Output is correct
34 Correct 18 ms 2132 KB Output is correct
35 Correct 44 ms 2132 KB Output is correct
36 Correct 52 ms 2172 KB Output is correct
37 Correct 127 ms 2172 KB Output is correct
38 Correct 149 ms 2300 KB Output is correct
39 Correct 55 ms 2300 KB Output is correct
40 Correct 3 ms 2300 KB Output is correct
41 Correct 38 ms 2300 KB Output is correct
42 Correct 52 ms 2300 KB Output is correct
43 Correct 8 ms 2300 KB Output is correct
44 Correct 42 ms 2300 KB Output is correct
45 Correct 55 ms 2300 KB Output is correct
46 Correct 55 ms 2300 KB Output is correct
47 Correct 17 ms 2300 KB Output is correct
48 Correct 5 ms 2300 KB Output is correct
49 Correct 115 ms 2300 KB Output is correct
50 Correct 60 ms 2300 KB Output is correct
51 Correct 81 ms 2300 KB Output is correct
52 Correct 61 ms 2300 KB Output is correct
53 Correct 57 ms 2300 KB Output is correct
54 Correct 125 ms 2300 KB Output is correct
55 Correct 49 ms 2300 KB Output is correct
56 Correct 86 ms 2300 KB Output is correct
57 Correct 55 ms 2300 KB Output is correct
58 Correct 471 ms 2300 KB Output is correct
59 Correct 552 ms 2300 KB Output is correct
60 Correct 453 ms 2300 KB Output is correct
61 Correct 564 ms 2300 KB Output is correct
62 Correct 489 ms 2300 KB Output is correct
63 Correct 547 ms 2300 KB Output is correct
64 Correct 465 ms 2300 KB Output is correct
65 Correct 2 ms 2300 KB Output is correct
66 Correct 2 ms 2300 KB Output is correct
67 Correct 596 ms 2300 KB Output is correct
68 Correct 551 ms 2300 KB Output is correct
69 Correct 481 ms 2300 KB Output is correct
70 Correct 487 ms 2300 KB Output is correct
71 Correct 599 ms 2300 KB Output is correct
72 Correct 525 ms 2300 KB Output is correct
73 Correct 513 ms 2300 KB Output is correct
74 Correct 539 ms 2300 KB Output is correct
75 Correct 534 ms 2300 KB Output is correct
76 Correct 544 ms 2300 KB Output is correct
77 Correct 116 ms 2300 KB Output is correct
78 Correct 71 ms 2300 KB Output is correct
79 Correct 93 ms 2300 KB Output is correct
80 Correct 92 ms 2300 KB Output is correct
81 Correct 88 ms 2300 KB Output is correct
82 Correct 83 ms 2300 KB Output is correct
83 Correct 73 ms 2300 KB Output is correct
84 Correct 348 ms 2300 KB Output is correct
85 Correct 715 ms 2300 KB Output is correct
86 Correct 4 ms 2300 KB Output is correct
87 Correct 3 ms 2300 KB Output is correct
88 Correct 633 ms 2300 KB Output is correct
89 Correct 114 ms 2300 KB Output is correct
90 Correct 3 ms 2300 KB Output is correct