Submission #90309

# Submission time Handle Problem Language Result Execution time Memory
90309 2018-12-21T08:29:04 Z adlet Chessboard (IZhO18_chessboard) C++17
70 / 100
1643 ms 5800 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 = 1e18;
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 (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 (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 (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;
            }
        }
        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: In function 'll get_sidey(ll, ll, ll, ll, ll)':
chessboard.cpp:66:11: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
     if (x > xx | y > yy)
         ~~^~~~
chessboard.cpp: At global scope:
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 256 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 1 ms 500 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 2448 KB Output is correct
2 Correct 19 ms 2448 KB Output is correct
3 Correct 47 ms 2448 KB Output is correct
4 Correct 48 ms 2448 KB Output is correct
5 Correct 64 ms 2448 KB Output is correct
6 Correct 41 ms 2448 KB Output is correct
7 Correct 15 ms 2448 KB Output is correct
8 Correct 42 ms 2448 KB Output is correct
9 Correct 104 ms 3452 KB Output is correct
10 Correct 59 ms 3452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3452 KB Output is correct
2 Correct 2 ms 3452 KB Output is correct
3 Correct 2 ms 3452 KB Output is correct
4 Correct 3 ms 3452 KB Output is correct
5 Correct 2 ms 3452 KB Output is correct
6 Correct 2 ms 3452 KB Output is correct
7 Correct 3 ms 3452 KB Output is correct
8 Correct 2 ms 3452 KB Output is correct
9 Correct 2 ms 3452 KB Output is correct
10 Correct 2 ms 3452 KB Output is correct
11 Correct 2 ms 3452 KB Output is correct
12 Correct 2 ms 3452 KB Output is correct
13 Correct 2 ms 3452 KB Output is correct
14 Correct 3 ms 3452 KB Output is correct
15 Correct 2 ms 3452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3452 KB Output is correct
2 Correct 2 ms 3452 KB Output is correct
3 Correct 2 ms 3452 KB Output is correct
4 Correct 3 ms 3452 KB Output is correct
5 Correct 2 ms 3452 KB Output is correct
6 Correct 2 ms 3452 KB Output is correct
7 Correct 3 ms 3452 KB Output is correct
8 Correct 2 ms 3452 KB Output is correct
9 Correct 2 ms 3452 KB Output is correct
10 Correct 2 ms 3452 KB Output is correct
11 Correct 2 ms 3452 KB Output is correct
12 Correct 2 ms 3452 KB Output is correct
13 Correct 2 ms 3452 KB Output is correct
14 Correct 3 ms 3452 KB Output is correct
15 Correct 2 ms 3452 KB Output is correct
16 Correct 27 ms 3452 KB Output is correct
17 Correct 75 ms 3452 KB Output is correct
18 Correct 92 ms 3740 KB Output is correct
19 Correct 131 ms 3740 KB Output is correct
20 Correct 147 ms 3788 KB Output is correct
21 Correct 73 ms 3788 KB Output is correct
22 Correct 2 ms 3788 KB Output is correct
23 Correct 45 ms 3788 KB Output is correct
24 Correct 85 ms 3788 KB Output is correct
25 Correct 10 ms 3788 KB Output is correct
26 Correct 54 ms 3788 KB Output is correct
27 Correct 66 ms 3788 KB Output is correct
28 Correct 89 ms 3788 KB Output is correct
29 Correct 31 ms 3788 KB Output is correct
30 Correct 4 ms 3788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 2448 KB Output is correct
2 Correct 19 ms 2448 KB Output is correct
3 Correct 47 ms 2448 KB Output is correct
4 Correct 48 ms 2448 KB Output is correct
5 Correct 64 ms 2448 KB Output is correct
6 Correct 41 ms 2448 KB Output is correct
7 Correct 15 ms 2448 KB Output is correct
8 Correct 42 ms 2448 KB Output is correct
9 Correct 104 ms 3452 KB Output is correct
10 Correct 59 ms 3452 KB Output is correct
11 Correct 2 ms 3452 KB Output is correct
12 Correct 2 ms 3452 KB Output is correct
13 Correct 2 ms 3452 KB Output is correct
14 Correct 3 ms 3452 KB Output is correct
15 Correct 2 ms 3452 KB Output is correct
16 Correct 2 ms 3452 KB Output is correct
17 Correct 3 ms 3452 KB Output is correct
18 Correct 2 ms 3452 KB Output is correct
19 Correct 2 ms 3452 KB Output is correct
20 Correct 2 ms 3452 KB Output is correct
21 Correct 2 ms 3452 KB Output is correct
22 Correct 2 ms 3452 KB Output is correct
23 Correct 2 ms 3452 KB Output is correct
24 Correct 3 ms 3452 KB Output is correct
25 Correct 2 ms 3452 KB Output is correct
26 Correct 27 ms 3452 KB Output is correct
27 Correct 75 ms 3452 KB Output is correct
28 Correct 92 ms 3740 KB Output is correct
29 Correct 131 ms 3740 KB Output is correct
30 Correct 147 ms 3788 KB Output is correct
31 Correct 73 ms 3788 KB Output is correct
32 Correct 2 ms 3788 KB Output is correct
33 Correct 45 ms 3788 KB Output is correct
34 Correct 85 ms 3788 KB Output is correct
35 Correct 10 ms 3788 KB Output is correct
36 Correct 54 ms 3788 KB Output is correct
37 Correct 66 ms 3788 KB Output is correct
38 Correct 89 ms 3788 KB Output is correct
39 Correct 31 ms 3788 KB Output is correct
40 Correct 4 ms 3788 KB Output is correct
41 Correct 139 ms 3788 KB Output is correct
42 Correct 115 ms 3788 KB Output is correct
43 Correct 119 ms 3788 KB Output is correct
44 Correct 112 ms 3788 KB Output is correct
45 Correct 121 ms 3788 KB Output is correct
46 Correct 158 ms 3788 KB Output is correct
47 Correct 101 ms 3788 KB Output is correct
48 Correct 115 ms 3788 KB Output is correct
49 Correct 103 ms 3788 KB Output is correct
50 Correct 369 ms 3788 KB Output is correct
51 Correct 396 ms 3788 KB Output is correct
52 Correct 367 ms 3788 KB Output is correct
53 Correct 389 ms 3788 KB Output is correct
54 Correct 365 ms 3788 KB Output is correct
55 Correct 403 ms 3828 KB Output is correct
56 Correct 351 ms 3828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 1 ms 500 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 73 ms 2448 KB Output is correct
10 Correct 19 ms 2448 KB Output is correct
11 Correct 47 ms 2448 KB Output is correct
12 Correct 48 ms 2448 KB Output is correct
13 Correct 64 ms 2448 KB Output is correct
14 Correct 41 ms 2448 KB Output is correct
15 Correct 15 ms 2448 KB Output is correct
16 Correct 42 ms 2448 KB Output is correct
17 Correct 104 ms 3452 KB Output is correct
18 Correct 59 ms 3452 KB Output is correct
19 Correct 2 ms 3452 KB Output is correct
20 Correct 2 ms 3452 KB Output is correct
21 Correct 2 ms 3452 KB Output is correct
22 Correct 3 ms 3452 KB Output is correct
23 Correct 2 ms 3452 KB Output is correct
24 Correct 2 ms 3452 KB Output is correct
25 Correct 3 ms 3452 KB Output is correct
26 Correct 2 ms 3452 KB Output is correct
27 Correct 2 ms 3452 KB Output is correct
28 Correct 2 ms 3452 KB Output is correct
29 Correct 2 ms 3452 KB Output is correct
30 Correct 2 ms 3452 KB Output is correct
31 Correct 2 ms 3452 KB Output is correct
32 Correct 3 ms 3452 KB Output is correct
33 Correct 2 ms 3452 KB Output is correct
34 Correct 27 ms 3452 KB Output is correct
35 Correct 75 ms 3452 KB Output is correct
36 Correct 92 ms 3740 KB Output is correct
37 Correct 131 ms 3740 KB Output is correct
38 Correct 147 ms 3788 KB Output is correct
39 Correct 73 ms 3788 KB Output is correct
40 Correct 2 ms 3788 KB Output is correct
41 Correct 45 ms 3788 KB Output is correct
42 Correct 85 ms 3788 KB Output is correct
43 Correct 10 ms 3788 KB Output is correct
44 Correct 54 ms 3788 KB Output is correct
45 Correct 66 ms 3788 KB Output is correct
46 Correct 89 ms 3788 KB Output is correct
47 Correct 31 ms 3788 KB Output is correct
48 Correct 4 ms 3788 KB Output is correct
49 Correct 139 ms 3788 KB Output is correct
50 Correct 115 ms 3788 KB Output is correct
51 Correct 119 ms 3788 KB Output is correct
52 Correct 112 ms 3788 KB Output is correct
53 Correct 121 ms 3788 KB Output is correct
54 Correct 158 ms 3788 KB Output is correct
55 Correct 101 ms 3788 KB Output is correct
56 Correct 115 ms 3788 KB Output is correct
57 Correct 103 ms 3788 KB Output is correct
58 Correct 369 ms 3788 KB Output is correct
59 Correct 396 ms 3788 KB Output is correct
60 Correct 367 ms 3788 KB Output is correct
61 Correct 389 ms 3788 KB Output is correct
62 Correct 365 ms 3788 KB Output is correct
63 Correct 403 ms 3828 KB Output is correct
64 Correct 351 ms 3828 KB Output is correct
65 Correct 1 ms 3828 KB Output is correct
66 Correct 2 ms 3828 KB Output is correct
67 Incorrect 1643 ms 5800 KB Output isn't correct
68 Halted 0 ms 0 KB -