답안 #155158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155158 2019-09-26T17:19:25 Z srvlt Chessboard (IZhO18_chessboard) C++14
47 / 100
448 ms 6624 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse2,avx")
#include <bits/stdc++.h>
#define ll int
#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());
const int inf = 1e18, N = 1e5 + 3;
struct rect {
    int x = 0, y = 0, x2 = 0, y2 = 0;
};
int n, k, ans = inf, p[2][N], A, Z, S, W, B, L;
vector <rect> v;

int color(int x, int y) {
    int z = (x - 1) / A;
    int w = (y - 1) / A;
    return ((z + w + Z) & 1);
}

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

int getL() {
    int x = n / A;
    int a = ((x + 1) / 2) * A * A;
    int b = (x / 2) * A * A;
    int res = ((x + 1) / 2) * a + (x / 2) * b;
    if (Z == 0) {
        return res;
    }   else {
        return n * n - res;
    }
}

int getval(int x, int a, int b) {
    if (x < 1) {
        return 0;
    }
    int res = 0;
    int last = ((x - 1) / A) * A + 1;
    if (num(last) == 0) {
        res += (x - last + 1) * a;
    }   else {
        res += (x - last + 1) * b;
    }
    int q = (last - 1) / A;
    res += ((q + 1) / 2) * A * a;
    res += (q / 2) * A * b;
    return res;
}

int getans() {
    for (int i = 1; i <= n; i++) {
        p[0][i] = p[0][i - 1];
        p[1][i] = p[1][i - 1];
        if (color(i, 1)) {
            p[0][i]++;
        }   else {
            p[1][i]++;
        }
    }
    int res = 0;
    for (auto i : v) {
        int x = i.x, y = i.y, x2 = i.x2, y2 = i.y2;
        int v1 = p[0][x2] - p[0][x - 1];
        int v2 = p[1][x2] - p[1][x - 1];
        res += getval(y2, v1, v2) - getval(y - 1, v1, v2);
    }
    return res;
}

void solve(int tc) {
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        rect tmp;
        cin >> tmp.x >> tmp.y >> tmp.x2 >> tmp.y2;
        S += (tmp.x2 - tmp.x + 1) * (tmp.y2 - tmp.y + 1);
        v.pb(tmp);
    }
    vector <int> factors = {};
    for (int i = 1; i < n; i++) {
        if (n % i == 0) {
            factors.pb(i);
        }
    }
    assert(factors.size() <= 96);
    for (auto i : factors) {
        A = i;
        for (int j = 0; j < 2; j++) {
            Z = j;
            L = getL();
            W = getans();
            B = L - (S - W);
            ans = min(ans, W + B);
        }
    }
    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();
    }
}
# 결과 실행 시간 메모리 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 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 3424 KB Output is correct
2 Correct 13 ms 1524 KB Output is correct
3 Correct 31 ms 3048 KB Output is correct
4 Correct 29 ms 2540 KB Output is correct
5 Correct 38 ms 3048 KB Output is correct
6 Correct 26 ms 2544 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 26 ms 2540 KB Output is correct
9 Correct 60 ms 4588 KB Output is correct
10 Correct 35 ms 2632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 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 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 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 3 ms 376 KB Output is correct
16 Correct 26 ms 1520 KB Output is correct
17 Correct 49 ms 4620 KB Output is correct
18 Correct 86 ms 4584 KB Output is correct
19 Correct 396 ms 4588 KB Output is correct
20 Correct 448 ms 4584 KB Output is correct
21 Correct 47 ms 4584 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 65 ms 2544 KB Output is correct
24 Correct 78 ms 4588 KB Output is correct
25 Correct 16 ms 1016 KB Output is correct
26 Correct 49 ms 2544 KB Output is correct
27 Correct 82 ms 4624 KB Output is correct
28 Correct 83 ms 4712 KB Output is correct
29 Correct 21 ms 2540 KB Output is correct
30 Correct 4 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 3424 KB Output is correct
2 Correct 13 ms 1524 KB Output is correct
3 Correct 31 ms 3048 KB Output is correct
4 Correct 29 ms 2540 KB Output is correct
5 Correct 38 ms 3048 KB Output is correct
6 Correct 26 ms 2544 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 26 ms 2540 KB Output is correct
9 Correct 60 ms 4588 KB Output is correct
10 Correct 35 ms 2632 KB Output is correct
11 Correct 2 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 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 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 3 ms 376 KB Output is correct
26 Correct 26 ms 1520 KB Output is correct
27 Correct 49 ms 4620 KB Output is correct
28 Correct 86 ms 4584 KB Output is correct
29 Correct 396 ms 4588 KB Output is correct
30 Correct 448 ms 4584 KB Output is correct
31 Correct 47 ms 4584 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 65 ms 2544 KB Output is correct
34 Correct 78 ms 4588 KB Output is correct
35 Correct 16 ms 1016 KB Output is correct
36 Correct 49 ms 2544 KB Output is correct
37 Correct 82 ms 4624 KB Output is correct
38 Correct 83 ms 4712 KB Output is correct
39 Correct 21 ms 2540 KB Output is correct
40 Correct 4 ms 508 KB Output is correct
41 Correct 405 ms 4584 KB Output is correct
42 Correct 99 ms 5260 KB Output is correct
43 Correct 217 ms 4584 KB Output is correct
44 Correct 98 ms 4828 KB Output is correct
45 Correct 67 ms 5216 KB Output is correct
46 Correct 445 ms 4956 KB Output is correct
47 Correct 61 ms 4704 KB Output is correct
48 Correct 157 ms 4692 KB Output is correct
49 Correct 90 ms 4708 KB Output is correct
50 Runtime error 50 ms 6624 KB Execution killed with signal 11 (could be triggered by violating memory limits)
51 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 44 ms 3424 KB Output is correct
10 Correct 13 ms 1524 KB Output is correct
11 Correct 31 ms 3048 KB Output is correct
12 Correct 29 ms 2540 KB Output is correct
13 Correct 38 ms 3048 KB Output is correct
14 Correct 26 ms 2544 KB Output is correct
15 Correct 8 ms 1016 KB Output is correct
16 Correct 26 ms 2540 KB Output is correct
17 Correct 60 ms 4588 KB Output is correct
18 Correct 35 ms 2632 KB Output is correct
19 Correct 2 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 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 3 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 3 ms 376 KB Output is correct
34 Correct 26 ms 1520 KB Output is correct
35 Correct 49 ms 4620 KB Output is correct
36 Correct 86 ms 4584 KB Output is correct
37 Correct 396 ms 4588 KB Output is correct
38 Correct 448 ms 4584 KB Output is correct
39 Correct 47 ms 4584 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 65 ms 2544 KB Output is correct
42 Correct 78 ms 4588 KB Output is correct
43 Correct 16 ms 1016 KB Output is correct
44 Correct 49 ms 2544 KB Output is correct
45 Correct 82 ms 4624 KB Output is correct
46 Correct 83 ms 4712 KB Output is correct
47 Correct 21 ms 2540 KB Output is correct
48 Correct 4 ms 508 KB Output is correct
49 Correct 405 ms 4584 KB Output is correct
50 Correct 99 ms 5260 KB Output is correct
51 Correct 217 ms 4584 KB Output is correct
52 Correct 98 ms 4828 KB Output is correct
53 Correct 67 ms 5216 KB Output is correct
54 Correct 445 ms 4956 KB Output is correct
55 Correct 61 ms 4704 KB Output is correct
56 Correct 157 ms 4692 KB Output is correct
57 Correct 90 ms 4708 KB Output is correct
58 Runtime error 50 ms 6624 KB Execution killed with signal 11 (could be triggered by violating memory limits)
59 Halted 0 ms 0 KB -