답안 #80973

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
80973 2018-10-23T10:25:53 Z inom Chessboard (IZhO18_chessboard) C++14
70 / 100
748 ms 61344 KB
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
#define int long long
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define in freopen("A.in", "r", stdin);
#define out freopen("A.out", "w", stdout);

using namespace std;
  
const int N = 500500;
const int INF = 1e15;

int TN = 1;

int n, k, ans = INF;
pair<int, int> a[N];

int get(int a, int b, int c) {
    a--; b--;
    a /= c; b /= c;
    a++; b++;
    return a + b;
}

int calc(int x) {
    if (x == n) {
        return INF;
    }
    // если первая фигня должна быть белой;
    int res = (((n / x) * (n / x)) / 2) * x * x;
    for (int i = 1; i <= k; i++) {
        if (get(a[i].fi, a[i].se, x) % 2 == 0) {
            res++;
        }
        else {
            res--;
        }
    }
    // иначе;
    int tmp = (((n / x) * (n / x)) / 2 + (n / x) % 2) * x * x;
    for (int i = 1; i <= k; i++) {
        if (get(a[i].fi, a[i].se, x) % 2 == 0) {
            tmp--;
        }
        else {
            tmp++;
        }
    }
    return min(res, tmp);
}

void solve() {
    cin >> n >> k;
    for (int i = 1; i <= k; i++) {
        cin >> a[i].fi >> a[i].se >> a[i].fi >> a[i].se;
    }
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (i * i == n) {
                ans = min(ans, calc(i));
            }
            else {
                ans = min(ans, calc(i));
                ans = min(ans, calc(n / i));
            }
        }
    }
    cout << ans << "\n";
    return;
}

signed main() {
    // ios_base::sync_with_stdio(0);
    // in; out; // cin >> TN;
    while (TN--) solve();
    return 0;
 }                                                
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 616 KB Output is correct
4 Correct 2 ms 688 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 2 ms 688 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 3180 KB Output is correct
2 Correct 33 ms 3180 KB Output is correct
3 Correct 64 ms 4008 KB Output is correct
4 Correct 57 ms 5152 KB Output is correct
5 Correct 87 ms 6532 KB Output is correct
6 Correct 55 ms 6972 KB Output is correct
7 Correct 16 ms 6972 KB Output is correct
8 Correct 50 ms 7976 KB Output is correct
9 Correct 137 ms 11104 KB Output is correct
10 Correct 77 ms 11444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11444 KB Output is correct
2 Correct 2 ms 11444 KB Output is correct
3 Correct 3 ms 11444 KB Output is correct
4 Correct 5 ms 11444 KB Output is correct
5 Correct 3 ms 11444 KB Output is correct
6 Correct 3 ms 11444 KB Output is correct
7 Correct 3 ms 11444 KB Output is correct
8 Correct 3 ms 11444 KB Output is correct
9 Correct 2 ms 11444 KB Output is correct
10 Correct 2 ms 11444 KB Output is correct
11 Correct 2 ms 11444 KB Output is correct
12 Correct 2 ms 11444 KB Output is correct
13 Correct 3 ms 11444 KB Output is correct
14 Correct 3 ms 11444 KB Output is correct
15 Correct 3 ms 11444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11444 KB Output is correct
2 Correct 2 ms 11444 KB Output is correct
3 Correct 3 ms 11444 KB Output is correct
4 Correct 5 ms 11444 KB Output is correct
5 Correct 3 ms 11444 KB Output is correct
6 Correct 3 ms 11444 KB Output is correct
7 Correct 3 ms 11444 KB Output is correct
8 Correct 3 ms 11444 KB Output is correct
9 Correct 2 ms 11444 KB Output is correct
10 Correct 2 ms 11444 KB Output is correct
11 Correct 2 ms 11444 KB Output is correct
12 Correct 2 ms 11444 KB Output is correct
13 Correct 3 ms 11444 KB Output is correct
14 Correct 3 ms 11444 KB Output is correct
15 Correct 3 ms 11444 KB Output is correct
16 Correct 33 ms 11868 KB Output is correct
17 Correct 96 ms 13980 KB Output is correct
18 Correct 129 ms 15948 KB Output is correct
19 Correct 205 ms 17092 KB Output is correct
20 Correct 230 ms 18900 KB Output is correct
21 Correct 98 ms 19984 KB Output is correct
22 Correct 3 ms 19984 KB Output is correct
23 Correct 59 ms 20024 KB Output is correct
24 Correct 105 ms 22248 KB Output is correct
25 Correct 13 ms 22248 KB Output is correct
26 Correct 70 ms 22800 KB Output is correct
27 Correct 94 ms 24012 KB Output is correct
28 Correct 117 ms 26008 KB Output is correct
29 Correct 37 ms 26008 KB Output is correct
30 Correct 5 ms 26008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 3180 KB Output is correct
2 Correct 33 ms 3180 KB Output is correct
3 Correct 64 ms 4008 KB Output is correct
4 Correct 57 ms 5152 KB Output is correct
5 Correct 87 ms 6532 KB Output is correct
6 Correct 55 ms 6972 KB Output is correct
7 Correct 16 ms 6972 KB Output is correct
8 Correct 50 ms 7976 KB Output is correct
9 Correct 137 ms 11104 KB Output is correct
10 Correct 77 ms 11444 KB Output is correct
11 Correct 2 ms 11444 KB Output is correct
12 Correct 2 ms 11444 KB Output is correct
13 Correct 3 ms 11444 KB Output is correct
14 Correct 5 ms 11444 KB Output is correct
15 Correct 3 ms 11444 KB Output is correct
16 Correct 3 ms 11444 KB Output is correct
17 Correct 3 ms 11444 KB Output is correct
18 Correct 3 ms 11444 KB Output is correct
19 Correct 2 ms 11444 KB Output is correct
20 Correct 2 ms 11444 KB Output is correct
21 Correct 2 ms 11444 KB Output is correct
22 Correct 2 ms 11444 KB Output is correct
23 Correct 3 ms 11444 KB Output is correct
24 Correct 3 ms 11444 KB Output is correct
25 Correct 3 ms 11444 KB Output is correct
26 Correct 33 ms 11868 KB Output is correct
27 Correct 96 ms 13980 KB Output is correct
28 Correct 129 ms 15948 KB Output is correct
29 Correct 205 ms 17092 KB Output is correct
30 Correct 230 ms 18900 KB Output is correct
31 Correct 98 ms 19984 KB Output is correct
32 Correct 3 ms 19984 KB Output is correct
33 Correct 59 ms 20024 KB Output is correct
34 Correct 105 ms 22248 KB Output is correct
35 Correct 13 ms 22248 KB Output is correct
36 Correct 70 ms 22800 KB Output is correct
37 Correct 94 ms 24012 KB Output is correct
38 Correct 117 ms 26008 KB Output is correct
39 Correct 37 ms 26008 KB Output is correct
40 Correct 5 ms 26008 KB Output is correct
41 Correct 206 ms 28496 KB Output is correct
42 Correct 147 ms 30820 KB Output is correct
43 Correct 161 ms 32796 KB Output is correct
44 Correct 150 ms 35156 KB Output is correct
45 Correct 149 ms 37468 KB Output is correct
46 Correct 227 ms 39576 KB Output is correct
47 Correct 125 ms 41824 KB Output is correct
48 Correct 154 ms 43744 KB Output is correct
49 Correct 133 ms 45812 KB Output is correct
50 Correct 687 ms 48004 KB Output is correct
51 Correct 742 ms 50556 KB Output is correct
52 Correct 674 ms 52536 KB Output is correct
53 Correct 737 ms 54892 KB Output is correct
54 Correct 658 ms 56788 KB Output is correct
55 Correct 748 ms 59492 KB Output is correct
56 Correct 643 ms 61344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 616 KB Output is correct
4 Correct 2 ms 688 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 2 ms 688 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 97 ms 3180 KB Output is correct
10 Correct 33 ms 3180 KB Output is correct
11 Correct 64 ms 4008 KB Output is correct
12 Correct 57 ms 5152 KB Output is correct
13 Correct 87 ms 6532 KB Output is correct
14 Correct 55 ms 6972 KB Output is correct
15 Correct 16 ms 6972 KB Output is correct
16 Correct 50 ms 7976 KB Output is correct
17 Correct 137 ms 11104 KB Output is correct
18 Correct 77 ms 11444 KB Output is correct
19 Correct 2 ms 11444 KB Output is correct
20 Correct 2 ms 11444 KB Output is correct
21 Correct 3 ms 11444 KB Output is correct
22 Correct 5 ms 11444 KB Output is correct
23 Correct 3 ms 11444 KB Output is correct
24 Correct 3 ms 11444 KB Output is correct
25 Correct 3 ms 11444 KB Output is correct
26 Correct 3 ms 11444 KB Output is correct
27 Correct 2 ms 11444 KB Output is correct
28 Correct 2 ms 11444 KB Output is correct
29 Correct 2 ms 11444 KB Output is correct
30 Correct 2 ms 11444 KB Output is correct
31 Correct 3 ms 11444 KB Output is correct
32 Correct 3 ms 11444 KB Output is correct
33 Correct 3 ms 11444 KB Output is correct
34 Correct 33 ms 11868 KB Output is correct
35 Correct 96 ms 13980 KB Output is correct
36 Correct 129 ms 15948 KB Output is correct
37 Correct 205 ms 17092 KB Output is correct
38 Correct 230 ms 18900 KB Output is correct
39 Correct 98 ms 19984 KB Output is correct
40 Correct 3 ms 19984 KB Output is correct
41 Correct 59 ms 20024 KB Output is correct
42 Correct 105 ms 22248 KB Output is correct
43 Correct 13 ms 22248 KB Output is correct
44 Correct 70 ms 22800 KB Output is correct
45 Correct 94 ms 24012 KB Output is correct
46 Correct 117 ms 26008 KB Output is correct
47 Correct 37 ms 26008 KB Output is correct
48 Correct 5 ms 26008 KB Output is correct
49 Correct 206 ms 28496 KB Output is correct
50 Correct 147 ms 30820 KB Output is correct
51 Correct 161 ms 32796 KB Output is correct
52 Correct 150 ms 35156 KB Output is correct
53 Correct 149 ms 37468 KB Output is correct
54 Correct 227 ms 39576 KB Output is correct
55 Correct 125 ms 41824 KB Output is correct
56 Correct 154 ms 43744 KB Output is correct
57 Correct 133 ms 45812 KB Output is correct
58 Correct 687 ms 48004 KB Output is correct
59 Correct 742 ms 50556 KB Output is correct
60 Correct 674 ms 52536 KB Output is correct
61 Correct 737 ms 54892 KB Output is correct
62 Correct 658 ms 56788 KB Output is correct
63 Correct 748 ms 59492 KB Output is correct
64 Correct 643 ms 61344 KB Output is correct
65 Correct 2 ms 61344 KB Output is correct
66 Incorrect 2 ms 61344 KB Output isn't correct
67 Halted 0 ms 0 KB -