답안 #518759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
518759 2022-01-24T14:46:01 Z spike1236 Chessboard (IZhO18_chessboard) C++14
70 / 100
609 ms 2700 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define ld long double
#define all(_v) _v.begin(), _v.end()
#define sz(_v) (int)_v.size()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define veci vector <int>
#define vecll vector <ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 1e5 + 10;
ll n;
ll cnt[MAXN];
veci dv;

ll get(ll r, ll k) {
    ll nr = (r % k == 0 ? r : r - r % k);
    ll bl = nr / k;
    ll cnt = (bl + 1) / 2 * k;
    if(bl % 2 == 0) cnt += r - nr;
    return cnt;
}

void solve() {
    int k;
    cin >> n >> k;
    dv.pb(1);
    for(int i = 2; i * i <= n; ++i) {
        if(n % i == 0) {
            dv.pb(i);
            if(i * i != n) dv.pb(n / i);
        }
    }
    sort(all(dv));
    for(auto i : dv) {
        ll cnt1 = get(n, i);
        cnt[i] = cnt1 * i * (((n / i) + 1) / 2) + (n - cnt1) * i * (n / i - (((n / i) + 1) / 2));
    }
    for(int rect = 1; rect <= k; ++rect) {
        ll x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        for(auto i : dv) {
            ll row_cnt[2];
            row_cnt[1] = get(x2, i) - get(x1 - 1, i);
            row_cnt[0] = x2 - x1 + 1 - row_cnt[1];
            ll col_cnt[2];
            col_cnt[1] = get(y2, i) - get(y2 - 1, i);
            col_cnt[0] = y2 - y1 + 1 - col_cnt[1];
            cnt[i] -= row_cnt[1] * col_cnt[1];
            cnt[i] -= row_cnt[0] * col_cnt[0];
            cnt[i] += row_cnt[0] * col_cnt[1];
            cnt[i] += row_cnt[1] * col_cnt[0];
        }
    }
    ll ans = 1e18;
    for(auto i : dv) ans = min(ans, min(cnt[i], n * n - cnt[i]));
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int CNT_TESTS = 1;
    ///cin >> CNT_TESTS;
    for(int NUMCASE = 1; NUMCASE <= CNT_TESTS; ++NUMCASE) {
        solve();
        if(NUMCASE != CNT_TESTS) cout << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1648 KB Output is correct
2 Correct 6 ms 672 KB Output is correct
3 Correct 15 ms 1232 KB Output is correct
4 Correct 14 ms 1084 KB Output is correct
5 Correct 25 ms 1576 KB Output is correct
6 Correct 14 ms 1060 KB Output is correct
7 Correct 3 ms 436 KB Output is correct
8 Correct 13 ms 1104 KB Output is correct
9 Correct 32 ms 2340 KB Output is correct
10 Correct 17 ms 1456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 10 ms 720 KB Output is correct
17 Correct 26 ms 1568 KB Output is correct
18 Correct 35 ms 1864 KB Output is correct
19 Correct 121 ms 1700 KB Output is correct
20 Correct 131 ms 1844 KB Output is correct
21 Correct 27 ms 1700 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 23 ms 948 KB Output is correct
24 Correct 32 ms 1772 KB Output is correct
25 Correct 5 ms 440 KB Output is correct
26 Correct 20 ms 1184 KB Output is correct
27 Correct 38 ms 1480 KB Output is correct
28 Correct 37 ms 1836 KB Output is correct
29 Correct 11 ms 848 KB Output is correct
30 Correct 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1648 KB Output is correct
2 Correct 6 ms 672 KB Output is correct
3 Correct 15 ms 1232 KB Output is correct
4 Correct 14 ms 1084 KB Output is correct
5 Correct 25 ms 1576 KB Output is correct
6 Correct 14 ms 1060 KB Output is correct
7 Correct 3 ms 436 KB Output is correct
8 Correct 13 ms 1104 KB Output is correct
9 Correct 32 ms 2340 KB Output is correct
10 Correct 17 ms 1456 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 0 ms 208 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 10 ms 720 KB Output is correct
27 Correct 26 ms 1568 KB Output is correct
28 Correct 35 ms 1864 KB Output is correct
29 Correct 121 ms 1700 KB Output is correct
30 Correct 131 ms 1844 KB Output is correct
31 Correct 27 ms 1700 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 23 ms 948 KB Output is correct
34 Correct 32 ms 1772 KB Output is correct
35 Correct 5 ms 440 KB Output is correct
36 Correct 20 ms 1184 KB Output is correct
37 Correct 38 ms 1480 KB Output is correct
38 Correct 37 ms 1836 KB Output is correct
39 Correct 11 ms 848 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 114 ms 2336 KB Output is correct
42 Correct 41 ms 2476 KB Output is correct
43 Correct 67 ms 2240 KB Output is correct
44 Correct 39 ms 2376 KB Output is correct
45 Correct 33 ms 2596 KB Output is correct
46 Correct 129 ms 2504 KB Output is correct
47 Correct 29 ms 2336 KB Output is correct
48 Correct 56 ms 2356 KB Output is correct
49 Correct 36 ms 2228 KB Output is correct
50 Correct 554 ms 2564 KB Output is correct
51 Correct 609 ms 2700 KB Output is correct
52 Correct 577 ms 2428 KB Output is correct
53 Correct 592 ms 2688 KB Output is correct
54 Correct 532 ms 2504 KB Output is correct
55 Correct 607 ms 2680 KB Output is correct
56 Correct 526 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 22 ms 1648 KB Output is correct
10 Correct 6 ms 672 KB Output is correct
11 Correct 15 ms 1232 KB Output is correct
12 Correct 14 ms 1084 KB Output is correct
13 Correct 25 ms 1576 KB Output is correct
14 Correct 14 ms 1060 KB Output is correct
15 Correct 3 ms 436 KB Output is correct
16 Correct 13 ms 1104 KB Output is correct
17 Correct 32 ms 2340 KB Output is correct
18 Correct 17 ms 1456 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 10 ms 720 KB Output is correct
35 Correct 26 ms 1568 KB Output is correct
36 Correct 35 ms 1864 KB Output is correct
37 Correct 121 ms 1700 KB Output is correct
38 Correct 131 ms 1844 KB Output is correct
39 Correct 27 ms 1700 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 23 ms 948 KB Output is correct
42 Correct 32 ms 1772 KB Output is correct
43 Correct 5 ms 440 KB Output is correct
44 Correct 20 ms 1184 KB Output is correct
45 Correct 38 ms 1480 KB Output is correct
46 Correct 37 ms 1836 KB Output is correct
47 Correct 11 ms 848 KB Output is correct
48 Correct 2 ms 336 KB Output is correct
49 Correct 114 ms 2336 KB Output is correct
50 Correct 41 ms 2476 KB Output is correct
51 Correct 67 ms 2240 KB Output is correct
52 Correct 39 ms 2376 KB Output is correct
53 Correct 33 ms 2596 KB Output is correct
54 Correct 129 ms 2504 KB Output is correct
55 Correct 29 ms 2336 KB Output is correct
56 Correct 56 ms 2356 KB Output is correct
57 Correct 36 ms 2228 KB Output is correct
58 Correct 554 ms 2564 KB Output is correct
59 Correct 609 ms 2700 KB Output is correct
60 Correct 577 ms 2428 KB Output is correct
61 Correct 592 ms 2688 KB Output is correct
62 Correct 532 ms 2504 KB Output is correct
63 Correct 607 ms 2680 KB Output is correct
64 Correct 526 ms 2424 KB Output is correct
65 Correct 1 ms 208 KB Output is correct
66 Incorrect 1 ms 208 KB Output isn't correct
67 Halted 0 ms 0 KB -