Submission #90329

# Submission time Handle Problem Language Result Execution time Memory
90329 2018-12-21T09:09:53 Z adlet Chessboard (IZhO18_chessboard) C++17
70 / 100
1797 ms 3840 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;

typedef long long ll;

#define int ll
#define y1 sda

const int N = 1e5 + 5;
const ll INF = 2e18;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);

int n, k;

ll ans = INF, k_area;

vector < int > v;

ll get(int x, int y, int xx, int yy, int len) {
    if (min({x, xx, y, yy}) < 0 || x > xx || y > yy)
        return 0;
    int f = ((x / len) % 2 == (y / len) % 2);
    x = (xx - x + 1) / len;
    y = (yy - y + 1) / len;
    ll num = (x * y) / 2;
    if (f) {
        num += ((x * y) % 2);
    }
    return num * len * len;
}

ll get_corner(int x, int y, int xx, int yy, int len) {
    if (min({x, xx, y, yy}) < 0 || x > xx || y > yy)
        return 0;
    int f = (((x / len) % 2) == ((y / len) % 2));
    x = (xx - x + 1);
    y = (yy - y + 1);
    ll num = (x * y) * f;
    return num;
}

int left(int l, int len) {
    return ((l + (len - 1)) / len) * len;
}

int right(int r, int len) {
    return (((r + 1) / len) * len) - 1;
}

ll get_sidex(int x, int y, int xx, int yy, int len) {
    if (min({x, xx, y, yy}) < 0 || x > xx || y > yy)
        return 0;
    int f = ((x / len) % 2) == ((y / len) % 2);
    y = yy - y + 1;
    x = (xx - x + 1) / len;
    ll num = (x / 2) + f * (x % 2);
    return num * y * len;
}

ll get_sidey(int x, int y, int xx, int yy, int len) {
    if (x > xx || y > yy)
        return 0;
    int f = ((x / len) % 2) == ((y / len) % 2);
    y = (yy - y + 1) / len;
    x = xx - x + 1;
    ll num = (y / 2) + f * (y % 2);
    return num * x * len;
}

ll get_one(int x, int y, int len) {
    return (((x / len) % 2) == ((y / len) % 2));
}

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

main() {
    cin >> n >> k;
    for (int i = 1; i <= k; ++i) {
        cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        x1[i]--;
        y1[i]--;
        x2[i]--;
        y2[i]--;
        k_area += (y2[i] - y1[i] + 1) * (x2[i] - x1[i] + 1);
    }
    v.push_back(1);
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            v.push_back(i);
            if (n / i != i) {
                v.push_back(n / i);
            }
        }
    }
//    cout << k_area << "\n";
    for (int i : v) {
        int m = n / i, cnt_black = 0, cnt_white = 0;
        ll black = (((m * m) / 2) + ((m * m) % 2)) * (i * 1ll * i);
        ll white = (n * 1ll * n) - black;
//        cout << i << " " << m << " " << black << " " << white << "\n";
        for (int j = 1; j <= k; ++j) {
            if (x1[j] == x2[j] && y1[j] == y2[j]) {
                cnt_black += get_one(x1[j], y1[j], i);
            } else {
                int px1 = -1, px2 = -1, py1 = -1, py2 = -1;
                ll center_black = 0, corner_black = 0, side_black = 0;
                px1 = left(x1[j], i);
                py1 = left(y1[j], i);
                px2 = right(x2[j], i);
                py2 = right(y2[j], i);
                center_black = get(px1, py1, px2, py2, i);
                corner_black = get_corner(x1[j], y1[j], px1 - 1, py1 - 1, i) +
                               get_corner(px2 + 1, y1[j], x2[j], py1 - 1, i) +
                               get_corner(x1[j], py2 + 1, px1 - 1, y2[j], i) +
                               get_corner(px2 + 1, py2 + 1, x2[j], y2[j], i);
                side_black = get_sidex(px1, y1[j], px2, py1 - 1, i) + get_sidex(px1, py2 + 1, px2, y2[j], i) +
                             get_sidey(x1[j], py1, px1 - 1, py2, i) + get_sidey(px2 + 1, py1, x2[j], py2, i);
                cnt_black += center_black + corner_black + side_black;
//                cout << "\t" << j << " " << px1 << " " << py1 << " " << px2 << " " << py2 << "\n";
//                cout << "\t\t" << center_black << " " << corner_black << " " << side_black << "\n";
            }
        }
        cnt_white = k_area - cnt_black;
        ll fx = (black - cnt_black) + cnt_white;
        ll fy = (white - cnt_white) + cnt_black;
//        cout << cnt_black << " " << cnt_white << " " << fx << " " << fy << "\n\n";
        ans = min(ans, min(fx, fy));
    }
    cout << ans;
}

Compilation message

chessboard.cpp:81:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 1 ms 484 KB Output is correct
5 Correct 1 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 484 KB Output is correct
8 Correct 2 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 2552 KB Output is correct
2 Correct 19 ms 2552 KB Output is correct
3 Correct 48 ms 2552 KB Output is correct
4 Correct 46 ms 2552 KB Output is correct
5 Correct 64 ms 2552 KB Output is correct
6 Correct 41 ms 2552 KB Output is correct
7 Correct 10 ms 2552 KB Output is correct
8 Correct 41 ms 2552 KB Output is correct
9 Correct 104 ms 3404 KB Output is correct
10 Correct 58 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 3 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 3 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 28 ms 3404 KB Output is correct
17 Correct 77 ms 3404 KB Output is correct
18 Correct 90 ms 3680 KB Output is correct
19 Correct 127 ms 3680 KB Output is correct
20 Correct 144 ms 3708 KB Output is correct
21 Correct 71 ms 3708 KB Output is correct
22 Correct 2 ms 3708 KB Output is correct
23 Correct 44 ms 3708 KB Output is correct
24 Correct 84 ms 3708 KB Output is correct
25 Correct 10 ms 3708 KB Output is correct
26 Correct 53 ms 3708 KB Output is correct
27 Correct 66 ms 3708 KB Output is correct
28 Correct 88 ms 3708 KB Output is correct
29 Correct 31 ms 3708 KB Output is correct
30 Correct 4 ms 3708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 2552 KB Output is correct
2 Correct 19 ms 2552 KB Output is correct
3 Correct 48 ms 2552 KB Output is correct
4 Correct 46 ms 2552 KB Output is correct
5 Correct 64 ms 2552 KB Output is correct
6 Correct 41 ms 2552 KB Output is correct
7 Correct 10 ms 2552 KB Output is correct
8 Correct 41 ms 2552 KB Output is correct
9 Correct 104 ms 3404 KB Output is correct
10 Correct 58 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
14 Correct 3 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 2 ms 3404 KB Output is correct
19 Correct 2 ms 3404 KB Output is correct
20 Correct 2 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 2 ms 3404 KB Output is correct
23 Correct 3 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
26 Correct 28 ms 3404 KB Output is correct
27 Correct 77 ms 3404 KB Output is correct
28 Correct 90 ms 3680 KB Output is correct
29 Correct 127 ms 3680 KB Output is correct
30 Correct 144 ms 3708 KB Output is correct
31 Correct 71 ms 3708 KB Output is correct
32 Correct 2 ms 3708 KB Output is correct
33 Correct 44 ms 3708 KB Output is correct
34 Correct 84 ms 3708 KB Output is correct
35 Correct 10 ms 3708 KB Output is correct
36 Correct 53 ms 3708 KB Output is correct
37 Correct 66 ms 3708 KB Output is correct
38 Correct 88 ms 3708 KB Output is correct
39 Correct 31 ms 3708 KB Output is correct
40 Correct 4 ms 3708 KB Output is correct
41 Correct 140 ms 3708 KB Output is correct
42 Correct 116 ms 3708 KB Output is correct
43 Correct 119 ms 3708 KB Output is correct
44 Correct 111 ms 3708 KB Output is correct
45 Correct 118 ms 3708 KB Output is correct
46 Correct 154 ms 3708 KB Output is correct
47 Correct 102 ms 3708 KB Output is correct
48 Correct 121 ms 3708 KB Output is correct
49 Correct 104 ms 3708 KB Output is correct
50 Correct 355 ms 3708 KB Output is correct
51 Correct 385 ms 3708 KB Output is correct
52 Correct 364 ms 3708 KB Output is correct
53 Correct 397 ms 3708 KB Output is correct
54 Correct 353 ms 3708 KB Output is correct
55 Correct 397 ms 3840 KB Output is correct
56 Correct 341 ms 3840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 1 ms 484 KB Output is correct
5 Correct 1 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 484 KB Output is correct
8 Correct 2 ms 484 KB Output is correct
9 Correct 76 ms 2552 KB Output is correct
10 Correct 19 ms 2552 KB Output is correct
11 Correct 48 ms 2552 KB Output is correct
12 Correct 46 ms 2552 KB Output is correct
13 Correct 64 ms 2552 KB Output is correct
14 Correct 41 ms 2552 KB Output is correct
15 Correct 10 ms 2552 KB Output is correct
16 Correct 41 ms 2552 KB Output is correct
17 Correct 104 ms 3404 KB Output is correct
18 Correct 58 ms 3404 KB Output is correct
19 Correct 2 ms 3404 KB Output is correct
20 Correct 2 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
23 Correct 2 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
26 Correct 2 ms 3404 KB Output is correct
27 Correct 2 ms 3404 KB Output is correct
28 Correct 2 ms 3404 KB Output is correct
29 Correct 2 ms 3404 KB Output is correct
30 Correct 2 ms 3404 KB Output is correct
31 Correct 3 ms 3404 KB Output is correct
32 Correct 2 ms 3404 KB Output is correct
33 Correct 2 ms 3404 KB Output is correct
34 Correct 28 ms 3404 KB Output is correct
35 Correct 77 ms 3404 KB Output is correct
36 Correct 90 ms 3680 KB Output is correct
37 Correct 127 ms 3680 KB Output is correct
38 Correct 144 ms 3708 KB Output is correct
39 Correct 71 ms 3708 KB Output is correct
40 Correct 2 ms 3708 KB Output is correct
41 Correct 44 ms 3708 KB Output is correct
42 Correct 84 ms 3708 KB Output is correct
43 Correct 10 ms 3708 KB Output is correct
44 Correct 53 ms 3708 KB Output is correct
45 Correct 66 ms 3708 KB Output is correct
46 Correct 88 ms 3708 KB Output is correct
47 Correct 31 ms 3708 KB Output is correct
48 Correct 4 ms 3708 KB Output is correct
49 Correct 140 ms 3708 KB Output is correct
50 Correct 116 ms 3708 KB Output is correct
51 Correct 119 ms 3708 KB Output is correct
52 Correct 111 ms 3708 KB Output is correct
53 Correct 118 ms 3708 KB Output is correct
54 Correct 154 ms 3708 KB Output is correct
55 Correct 102 ms 3708 KB Output is correct
56 Correct 121 ms 3708 KB Output is correct
57 Correct 104 ms 3708 KB Output is correct
58 Correct 355 ms 3708 KB Output is correct
59 Correct 385 ms 3708 KB Output is correct
60 Correct 364 ms 3708 KB Output is correct
61 Correct 397 ms 3708 KB Output is correct
62 Correct 353 ms 3708 KB Output is correct
63 Correct 397 ms 3840 KB Output is correct
64 Correct 341 ms 3840 KB Output is correct
65 Correct 2 ms 3840 KB Output is correct
66 Correct 2 ms 3840 KB Output is correct
67 Incorrect 1797 ms 3840 KB Output isn't correct
68 Halted 0 ms 0 KB -