답안 #308702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308702 2020-10-01T17:29:03 Z aZvezda Chessboard (IZhO18_chessboard) C++14
100 / 100
845 ms 6008 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e11 + 7;
template<class T> inline void fix(T &x) {if(labs(x) >= mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const ll MAX_N = 1e5 + 110;
ll xl[MAX_N], yl[MAX_N], xr[MAX_N], yr[MAX_N];
ll n, k;
ll sz;

ll howm(ll w, ll l, ll r) {
    if(l / sz == r / sz) {
        if(l / sz % 2ll == w) {
            return r - l + 1ll;
        } else {
            return 0;
        }
    }
    ll ret = 0;
    {
        ll nxt = (l + sz) / sz * sz;
        if(l / sz % 2ll == w) {
            ret += nxt - l;
        }
        l = nxt;
    }
    {
        ll nxt = r / sz * sz - 1ll;
        if(r / sz % 2ll == w) {
            ret += r - nxt;
        }
        r = nxt;
    }
    ret += (r / sz - l / sz) / 2ll * sz;
    if(l / sz % 2ll == r / sz % 2ll && l / sz % 2ll == w) {
        ret += sz;
    }
    return ret;
}

ll eval(ll x) {
    sz = x;
    ll badw = 0, goodb = 0;
    ll cnt = (n * n) / (x * x);
    goodb = cnt / 2ll * sz * sz;
    for(ll i = 0; i < k; i ++) {
        ll r0 = howm(0, xl[i], xr[i]);
        ll r1 = howm(1, xl[i], xr[i]);
        ll c0 = howm(0, yl[i], yr[i]);
        ll c1 = howm(1, yl[i], yr[i]);
        badw += r0 * c0 + r1 * c1;
        goodb -= r0 * c1 + r1 * c0;
    }
    return min(badw + goodb, n * n - badw - goodb);
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


    cin >> n >> k;
    ll ans = mod;
    for(ll i = 0; i < k; i ++) {
        cin >> xl[i] >> yl[i] >> xr[i] >> yr[i];
        xl[i] --;
        yl[i] --;
        xr[i] --;
        yr[i] --;
    }
    for(ll x = 1; x < n; x ++) {
        if(n % x != 0) {continue;}
        chkmin(ans, eval(x));
    }
    cout << ans << endl;
    return 0;
}

/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 3832 KB Output is correct
2 Correct 10 ms 1196 KB Output is correct
3 Correct 19 ms 2616 KB Output is correct
4 Correct 42 ms 2680 KB Output is correct
5 Correct 25 ms 3328 KB Output is correct
6 Correct 17 ms 2212 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 18 ms 2304 KB Output is correct
9 Correct 41 ms 5240 KB Output is correct
10 Correct 23 ms 3072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 15 ms 1692 KB Output is correct
17 Correct 95 ms 4344 KB Output is correct
18 Correct 47 ms 5112 KB Output is correct
19 Correct 143 ms 4728 KB Output is correct
20 Correct 159 ms 4992 KB Output is correct
21 Correct 31 ms 4148 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 30 ms 2424 KB Output is correct
24 Correct 48 ms 4600 KB Output is correct
25 Correct 8 ms 768 KB Output is correct
26 Correct 26 ms 3072 KB Output is correct
27 Correct 40 ms 3576 KB Output is correct
28 Correct 47 ms 4856 KB Output is correct
29 Correct 16 ms 1920 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 3832 KB Output is correct
2 Correct 10 ms 1196 KB Output is correct
3 Correct 19 ms 2616 KB Output is correct
4 Correct 42 ms 2680 KB Output is correct
5 Correct 25 ms 3328 KB Output is correct
6 Correct 17 ms 2212 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 18 ms 2304 KB Output is correct
9 Correct 41 ms 5240 KB Output is correct
10 Correct 23 ms 3072 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 15 ms 1692 KB Output is correct
27 Correct 95 ms 4344 KB Output is correct
28 Correct 47 ms 5112 KB Output is correct
29 Correct 143 ms 4728 KB Output is correct
30 Correct 159 ms 4992 KB Output is correct
31 Correct 31 ms 4148 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 30 ms 2424 KB Output is correct
34 Correct 48 ms 4600 KB Output is correct
35 Correct 8 ms 768 KB Output is correct
36 Correct 26 ms 3072 KB Output is correct
37 Correct 40 ms 3576 KB Output is correct
38 Correct 47 ms 4856 KB Output is correct
39 Correct 16 ms 1920 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 172 ms 4992 KB Output is correct
42 Correct 59 ms 5496 KB Output is correct
43 Correct 116 ms 5020 KB Output is correct
44 Correct 50 ms 5368 KB Output is correct
45 Correct 44 ms 5752 KB Output is correct
46 Correct 148 ms 5536 KB Output is correct
47 Correct 58 ms 5112 KB Output is correct
48 Correct 70 ms 5112 KB Output is correct
49 Correct 46 ms 4984 KB Output is correct
50 Correct 637 ms 5368 KB Output is correct
51 Correct 680 ms 5768 KB Output is correct
52 Correct 659 ms 5496 KB Output is correct
53 Correct 709 ms 5728 KB Output is correct
54 Correct 621 ms 5368 KB Output is correct
55 Correct 706 ms 5920 KB Output is correct
56 Correct 605 ms 5176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 29 ms 3832 KB Output is correct
10 Correct 10 ms 1196 KB Output is correct
11 Correct 19 ms 2616 KB Output is correct
12 Correct 42 ms 2680 KB Output is correct
13 Correct 25 ms 3328 KB Output is correct
14 Correct 17 ms 2212 KB Output is correct
15 Correct 4 ms 768 KB Output is correct
16 Correct 18 ms 2304 KB Output is correct
17 Correct 41 ms 5240 KB Output is correct
18 Correct 23 ms 3072 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 15 ms 1692 KB Output is correct
35 Correct 95 ms 4344 KB Output is correct
36 Correct 47 ms 5112 KB Output is correct
37 Correct 143 ms 4728 KB Output is correct
38 Correct 159 ms 4992 KB Output is correct
39 Correct 31 ms 4148 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 30 ms 2424 KB Output is correct
42 Correct 48 ms 4600 KB Output is correct
43 Correct 8 ms 768 KB Output is correct
44 Correct 26 ms 3072 KB Output is correct
45 Correct 40 ms 3576 KB Output is correct
46 Correct 47 ms 4856 KB Output is correct
47 Correct 16 ms 1920 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 172 ms 4992 KB Output is correct
50 Correct 59 ms 5496 KB Output is correct
51 Correct 116 ms 5020 KB Output is correct
52 Correct 50 ms 5368 KB Output is correct
53 Correct 44 ms 5752 KB Output is correct
54 Correct 148 ms 5536 KB Output is correct
55 Correct 58 ms 5112 KB Output is correct
56 Correct 70 ms 5112 KB Output is correct
57 Correct 46 ms 4984 KB Output is correct
58 Correct 637 ms 5368 KB Output is correct
59 Correct 680 ms 5768 KB Output is correct
60 Correct 659 ms 5496 KB Output is correct
61 Correct 709 ms 5728 KB Output is correct
62 Correct 621 ms 5368 KB Output is correct
63 Correct 706 ms 5920 KB Output is correct
64 Correct 605 ms 5176 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 784 ms 5576 KB Output is correct
68 Correct 799 ms 5624 KB Output is correct
69 Correct 681 ms 4912 KB Output is correct
70 Correct 740 ms 5368 KB Output is correct
71 Correct 722 ms 5328 KB Output is correct
72 Correct 710 ms 5240 KB Output is correct
73 Correct 786 ms 5112 KB Output is correct
74 Correct 845 ms 5624 KB Output is correct
75 Correct 729 ms 5240 KB Output is correct
76 Correct 782 ms 5496 KB Output is correct
77 Correct 136 ms 5880 KB Output is correct
78 Correct 56 ms 5248 KB Output is correct
79 Correct 96 ms 4984 KB Output is correct
80 Correct 102 ms 5248 KB Output is correct
81 Correct 95 ms 4984 KB Output is correct
82 Correct 85 ms 5496 KB Output is correct
83 Correct 67 ms 5112 KB Output is correct
84 Correct 469 ms 5752 KB Output is correct
85 Correct 795 ms 5752 KB Output is correct
86 Correct 2 ms 384 KB Output is correct
87 Correct 1 ms 384 KB Output is correct
88 Correct 811 ms 6008 KB Output is correct
89 Correct 160 ms 1408 KB Output is correct
90 Correct 2 ms 384 KB Output is correct