Submission #155380

# Submission time Handle Problem Language Result Execution time Memory
155380 2019-09-27T17:20:13 Z srvlt Chessboard (IZhO18_chessboard) C++14
70 / 100
1886 ms 3520 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse2,avx")
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define int long long
using namespace std;

void dout() {
    cerr << endl;
}

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
const int N = 1e5 + 7, inf = 1e18;
int n, k, x[N], y[N], x2[N], y2[N], ans = inf;
int A, S;

int num(int x) {
    return ((x - 1) / A) & 1;
}

int open(int x) {
    if (x == 0) {
        return 0;
    }
    return (x - 1) / A + 1;
}

int close(int x) {
    return x / A;
}

int last_close(int x) {
    return close(x) * A;
}

int next_close(int x) {
    int tmp = last_close(x);
    if (x == tmp) {
        return x;
    }
    return tmp + A;
}

int last_open(int x) {
    return (open(x) - 1) * A + 1;
}

int next_open(int x) {
    int tmp = last_open(x);
    if (x == tmp) {
        return x;
    }
    return tmp + A;
}

pii get_colors(int l, int r) {
    int blocks = close(r) - open(l - 1);
    int a = 0, b = 0;
    if (blocks > 0) {
        if (num(l) == 0) {
            a += next_open(l) - l;

            a += ((blocks + 1) / 2) * A;
            b += (blocks / 2) * A;
        }   else {
            b += next_open(l) - l;

            a += (blocks / 2) * A;
            b += ((blocks + 1) / 2) * A;
        }
        if (num(r) == 0) {
            a += r - last_close(r);
        }   else {
            b += r - last_close(r);
        }
    }   else {
        if (num(l) == 0) {
            a += next_open(l) - l;
        }   else {
            b += next_open(l) - l;
        }
        if (num(r) == 0) {
            a += r - next_open(l) + 1;
        }   else {
            b += r - next_open(l) + 1;
        }
    }
    return {a, b};
}

pii get_squares() {
    int even = (n / A) / 2, odd = ((n / A) + 1) / 2;
    int a = even * odd + odd * even;
    int b = odd * odd + even * even;
    return {a * A * A, b * A * A};
}

int get_color(int x, int y, int z) {
    return (num(x) + num(y) + z) & 1;
}

int get_ans() {
    int res0 = 0, res1 = 0;
    for (int i = 0; i < k; i++) {
        pii t1 = get_colors(y[i], y2[i]);
        pii t2 = get_colors(x[i], x2[i]);
        int a = t2.fi, b = t2.se;
        int c = t1.fi, d = t1.se;

        res0 += a * c + b * d;
        res1 += b * c + a * d;
    }
    pii tmp = get_squares();
    return min(tmp.se - S + 2LL * res1, tmp.fi - S + 2LL * res0);
}

void solve(int tc) {
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        cin >> x[i] >> y[i] >> x2[i] >> y2[i];
        S += (x2[i] - x[i] + 1) * (y2[i] - y[i] + 1);
    }
    for (int i = 1; i < n; i++) {
        if (n % i == 0) {
            A = i;
            ans = min(ans, get_ans());
        }
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 2424 KB Output is correct
2 Correct 12 ms 1016 KB Output is correct
3 Correct 27 ms 1784 KB Output is correct
4 Correct 28 ms 1884 KB Output is correct
5 Correct 35 ms 2040 KB Output is correct
6 Correct 23 ms 1528 KB Output is correct
7 Correct 7 ms 624 KB Output is correct
8 Correct 23 ms 1528 KB Output is correct
9 Correct 57 ms 3192 KB Output is correct
10 Correct 33 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 424 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 424 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 4 ms 376 KB Output is correct
16 Correct 24 ms 1272 KB Output is correct
17 Correct 47 ms 2936 KB Output is correct
18 Correct 81 ms 3488 KB Output is correct
19 Correct 387 ms 3192 KB Output is correct
20 Correct 423 ms 3488 KB Output is correct
21 Correct 42 ms 2936 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 72 ms 1784 KB Output is correct
24 Correct 76 ms 3192 KB Output is correct
25 Correct 14 ms 632 KB Output is correct
26 Correct 49 ms 2140 KB Output is correct
27 Correct 76 ms 2552 KB Output is correct
28 Correct 79 ms 3292 KB Output is correct
29 Correct 20 ms 1400 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 2424 KB Output is correct
2 Correct 12 ms 1016 KB Output is correct
3 Correct 27 ms 1784 KB Output is correct
4 Correct 28 ms 1884 KB Output is correct
5 Correct 35 ms 2040 KB Output is correct
6 Correct 23 ms 1528 KB Output is correct
7 Correct 7 ms 624 KB Output is correct
8 Correct 23 ms 1528 KB Output is correct
9 Correct 57 ms 3192 KB Output is correct
10 Correct 33 ms 1912 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 424 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 4 ms 376 KB Output is correct
26 Correct 24 ms 1272 KB Output is correct
27 Correct 47 ms 2936 KB Output is correct
28 Correct 81 ms 3488 KB Output is correct
29 Correct 387 ms 3192 KB Output is correct
30 Correct 423 ms 3488 KB Output is correct
31 Correct 42 ms 2936 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 72 ms 1784 KB Output is correct
34 Correct 76 ms 3192 KB Output is correct
35 Correct 14 ms 632 KB Output is correct
36 Correct 49 ms 2140 KB Output is correct
37 Correct 76 ms 2552 KB Output is correct
38 Correct 79 ms 3292 KB Output is correct
39 Correct 20 ms 1400 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 324 ms 2992 KB Output is correct
42 Correct 86 ms 3320 KB Output is correct
43 Correct 172 ms 3040 KB Output is correct
44 Correct 81 ms 3192 KB Output is correct
45 Correct 60 ms 3448 KB Output is correct
46 Correct 354 ms 3324 KB Output is correct
47 Correct 53 ms 3068 KB Output is correct
48 Correct 129 ms 3124 KB Output is correct
49 Correct 76 ms 3064 KB Output is correct
50 Correct 1723 ms 3232 KB Output is correct
51 Correct 1840 ms 3448 KB Output is correct
52 Correct 1708 ms 3320 KB Output is correct
53 Correct 1886 ms 3324 KB Output is correct
54 Correct 1706 ms 3064 KB Output is correct
55 Correct 1874 ms 3520 KB Output is correct
56 Correct 1619 ms 3092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 39 ms 2424 KB Output is correct
10 Correct 12 ms 1016 KB Output is correct
11 Correct 27 ms 1784 KB Output is correct
12 Correct 28 ms 1884 KB Output is correct
13 Correct 35 ms 2040 KB Output is correct
14 Correct 23 ms 1528 KB Output is correct
15 Correct 7 ms 624 KB Output is correct
16 Correct 23 ms 1528 KB Output is correct
17 Correct 57 ms 3192 KB Output is correct
18 Correct 33 ms 1912 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 424 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 4 ms 376 KB Output is correct
34 Correct 24 ms 1272 KB Output is correct
35 Correct 47 ms 2936 KB Output is correct
36 Correct 81 ms 3488 KB Output is correct
37 Correct 387 ms 3192 KB Output is correct
38 Correct 423 ms 3488 KB Output is correct
39 Correct 42 ms 2936 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 72 ms 1784 KB Output is correct
42 Correct 76 ms 3192 KB Output is correct
43 Correct 14 ms 632 KB Output is correct
44 Correct 49 ms 2140 KB Output is correct
45 Correct 76 ms 2552 KB Output is correct
46 Correct 79 ms 3292 KB Output is correct
47 Correct 20 ms 1400 KB Output is correct
48 Correct 4 ms 376 KB Output is correct
49 Correct 324 ms 2992 KB Output is correct
50 Correct 86 ms 3320 KB Output is correct
51 Correct 172 ms 3040 KB Output is correct
52 Correct 81 ms 3192 KB Output is correct
53 Correct 60 ms 3448 KB Output is correct
54 Correct 354 ms 3324 KB Output is correct
55 Correct 53 ms 3068 KB Output is correct
56 Correct 129 ms 3124 KB Output is correct
57 Correct 76 ms 3064 KB Output is correct
58 Correct 1723 ms 3232 KB Output is correct
59 Correct 1840 ms 3448 KB Output is correct
60 Correct 1708 ms 3320 KB Output is correct
61 Correct 1886 ms 3324 KB Output is correct
62 Correct 1706 ms 3064 KB Output is correct
63 Correct 1874 ms 3520 KB Output is correct
64 Correct 1619 ms 3092 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Incorrect 1806 ms 3320 KB Output isn't correct
68 Halted 0 ms 0 KB -