답안 #518766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
518766 2022-01-24T14:49:39 Z spike1236 Chessboard (IZhO18_chessboard) C++14
70 / 100
606 ms 452 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 = 2e5 + 10;
ll n;
ll cnt[MAXN];

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;
    vecll dv;
    dv.pb(1);
    for(ll 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 = 4e18;
    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 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 324 KB Output is correct
2 Correct 5 ms 204 KB Output is correct
3 Correct 13 ms 320 KB Output is correct
4 Correct 13 ms 320 KB Output is correct
5 Correct 17 ms 204 KB Output is correct
6 Correct 11 ms 312 KB Output is correct
7 Correct 3 ms 204 KB Output is correct
8 Correct 12 ms 204 KB Output is correct
9 Correct 30 ms 204 KB Output is correct
10 Correct 17 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 10 ms 204 KB Output is correct
17 Correct 22 ms 204 KB Output is correct
18 Correct 35 ms 204 KB Output is correct
19 Correct 120 ms 304 KB Output is correct
20 Correct 136 ms 300 KB Output is correct
21 Correct 21 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 22 ms 204 KB Output is correct
24 Correct 30 ms 204 KB Output is correct
25 Correct 4 ms 204 KB Output is correct
26 Correct 22 ms 204 KB Output is correct
27 Correct 29 ms 324 KB Output is correct
28 Correct 34 ms 204 KB Output is correct
29 Correct 9 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 324 KB Output is correct
2 Correct 5 ms 204 KB Output is correct
3 Correct 13 ms 320 KB Output is correct
4 Correct 13 ms 320 KB Output is correct
5 Correct 17 ms 204 KB Output is correct
6 Correct 11 ms 312 KB Output is correct
7 Correct 3 ms 204 KB Output is correct
8 Correct 12 ms 204 KB Output is correct
9 Correct 30 ms 204 KB Output is correct
10 Correct 17 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 10 ms 204 KB Output is correct
27 Correct 22 ms 204 KB Output is correct
28 Correct 35 ms 204 KB Output is correct
29 Correct 120 ms 304 KB Output is correct
30 Correct 136 ms 300 KB Output is correct
31 Correct 21 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 22 ms 204 KB Output is correct
34 Correct 30 ms 204 KB Output is correct
35 Correct 4 ms 204 KB Output is correct
36 Correct 22 ms 204 KB Output is correct
37 Correct 29 ms 324 KB Output is correct
38 Correct 34 ms 204 KB Output is correct
39 Correct 9 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 108 ms 336 KB Output is correct
42 Correct 38 ms 204 KB Output is correct
43 Correct 65 ms 332 KB Output is correct
44 Correct 39 ms 316 KB Output is correct
45 Correct 31 ms 204 KB Output is correct
46 Correct 128 ms 332 KB Output is correct
47 Correct 28 ms 204 KB Output is correct
48 Correct 51 ms 204 KB Output is correct
49 Correct 34 ms 300 KB Output is correct
50 Correct 541 ms 452 KB Output is correct
51 Correct 580 ms 388 KB Output is correct
52 Correct 539 ms 452 KB Output is correct
53 Correct 587 ms 384 KB Output is correct
54 Correct 540 ms 384 KB Output is correct
55 Correct 606 ms 396 KB Output is correct
56 Correct 513 ms 332 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 0 ms 204 KB Output is correct
9 Correct 21 ms 324 KB Output is correct
10 Correct 5 ms 204 KB Output is correct
11 Correct 13 ms 320 KB Output is correct
12 Correct 13 ms 320 KB Output is correct
13 Correct 17 ms 204 KB Output is correct
14 Correct 11 ms 312 KB Output is correct
15 Correct 3 ms 204 KB Output is correct
16 Correct 12 ms 204 KB Output is correct
17 Correct 30 ms 204 KB Output is correct
18 Correct 17 ms 316 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 10 ms 204 KB Output is correct
35 Correct 22 ms 204 KB Output is correct
36 Correct 35 ms 204 KB Output is correct
37 Correct 120 ms 304 KB Output is correct
38 Correct 136 ms 300 KB Output is correct
39 Correct 21 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 22 ms 204 KB Output is correct
42 Correct 30 ms 204 KB Output is correct
43 Correct 4 ms 204 KB Output is correct
44 Correct 22 ms 204 KB Output is correct
45 Correct 29 ms 324 KB Output is correct
46 Correct 34 ms 204 KB Output is correct
47 Correct 9 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 108 ms 336 KB Output is correct
50 Correct 38 ms 204 KB Output is correct
51 Correct 65 ms 332 KB Output is correct
52 Correct 39 ms 316 KB Output is correct
53 Correct 31 ms 204 KB Output is correct
54 Correct 128 ms 332 KB Output is correct
55 Correct 28 ms 204 KB Output is correct
56 Correct 51 ms 204 KB Output is correct
57 Correct 34 ms 300 KB Output is correct
58 Correct 541 ms 452 KB Output is correct
59 Correct 580 ms 388 KB Output is correct
60 Correct 539 ms 452 KB Output is correct
61 Correct 587 ms 384 KB Output is correct
62 Correct 540 ms 384 KB Output is correct
63 Correct 606 ms 396 KB Output is correct
64 Correct 513 ms 332 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Incorrect 0 ms 204 KB Output isn't correct
67 Halted 0 ms 0 KB -