답안 #448745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448745 2021-08-01T10:47:41 Z dxz05 Chessboard (IZhO18_chessboard) C++14
70 / 100
372 ms 3408 KB
#pragma GCC optimize("Ofast,O2,O3")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << "[" << H << "]";
    debug_out(T...);
}

#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define revall(x) (x).rbegin(), (x).rend()

clock_t startTime;

double getCurrentTime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}

#define MP make_pair

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 2e6 + 3e2;
const int M = 5222;

#define x first
#define y second

void solve(int TC) {
    int n, k;
    cin >> n >> k;

    vector<pair<int, int>> points(k);
    for (auto &p : points){
        cin >> p.x >> p.y >> p.x >> p.y;
    }

    vector<int> divisors;
    for (int d = 1; d < n; d++){
        if (n % d == 0) divisors.push_back(d);
    }

    ll ans = 1ll * n * n;

    for (int d : divisors){ /// (1, 1) = black
        ll cost = (1ll * (n / d) * (n / d) + 1) / 2 * d * d;
        for (auto p : points){
            int i = (p.x + d - 1) / d, j = (p.y + d - 1) / d;

            if ((i + j) % 2 == 0) cost--; else
                cost++;

            debug(d, i, j);
        }

        ans = min(ans, cost);
        debug(d, cost);
    }

    for (int d : divisors){ /// (1, 1) = black
        ll cost = 1ll * (n / d) * (n / d) / 2 * d * d;
        for (auto p : points){
            int i = (p.x + d - 1) / d, j = (p.y + d - 1) / d;

            if ((i + j) % 2 == 1) cost--; else
                cost++;

            debug(d, i, j);
        }

        ans = min(ans, cost);
        debug(d, cost);
    }

    cout << ans;

}

int main() {
    startTime = clock();
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    bool llololcal = false;
#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    llololcal = true;
#endif

    int TC = 1;
    //cin >> TC;

    for (int test = 1; test <= TC; test++) {
        debug(test);
        //cout << "Case #" << test << ": ";
        solve(test);
    }

    if (llololcal) cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;

    return 0;
}

Compilation message

chessboard.cpp: In function 'void solve(int)':
chessboard.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
chessboard.cpp:70:13: note: in expansion of macro 'debug'
   70 |             debug(d, i, j);
      |             ^~~~~
chessboard.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
chessboard.cpp:74:9: note: in expansion of macro 'debug'
   74 |         debug(d, cost);
      |         ^~~~~
chessboard.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
chessboard.cpp:85:13: note: in expansion of macro 'debug'
   85 |             debug(d, i, j);
      |             ^~~~~
chessboard.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
chessboard.cpp:89:9: note: in expansion of macro 'debug'
   89 |         debug(d, cost);
      |         ^~~~~
chessboard.cpp: In function 'int main()':
chessboard.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
chessboard.cpp:113:9: note: in expansion of macro 'debug'
  113 |         debug(test);
      |         ^~~~~
# 결과 실행 시간 메모리 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 0 ms 204 KB Output is correct
5 Correct 1 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 28 ms 2204 KB Output is correct
2 Correct 8 ms 716 KB Output is correct
3 Correct 18 ms 1520 KB Output is correct
4 Correct 19 ms 1440 KB Output is correct
5 Correct 25 ms 1996 KB Output is correct
6 Correct 16 ms 1356 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 16 ms 1360 KB Output is correct
9 Correct 41 ms 3056 KB Output is correct
10 Correct 22 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 12 ms 972 KB Output is correct
17 Correct 35 ms 2256 KB Output is correct
18 Correct 43 ms 2576 KB Output is correct
19 Correct 91 ms 2408 KB Output is correct
20 Correct 102 ms 2608 KB Output is correct
21 Correct 32 ms 2224 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 23 ms 1228 KB Output is correct
24 Correct 38 ms 2424 KB Output is correct
25 Correct 5 ms 456 KB Output is correct
26 Correct 26 ms 1612 KB Output is correct
27 Correct 32 ms 1872 KB Output is correct
28 Correct 42 ms 2604 KB Output is correct
29 Correct 13 ms 1084 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2204 KB Output is correct
2 Correct 8 ms 716 KB Output is correct
3 Correct 18 ms 1520 KB Output is correct
4 Correct 19 ms 1440 KB Output is correct
5 Correct 25 ms 1996 KB Output is correct
6 Correct 16 ms 1356 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 16 ms 1360 KB Output is correct
9 Correct 41 ms 3056 KB Output is correct
10 Correct 22 ms 1868 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 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 320 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 12 ms 972 KB Output is correct
27 Correct 35 ms 2256 KB Output is correct
28 Correct 43 ms 2576 KB Output is correct
29 Correct 91 ms 2408 KB Output is correct
30 Correct 102 ms 2608 KB Output is correct
31 Correct 32 ms 2224 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 23 ms 1228 KB Output is correct
34 Correct 38 ms 2424 KB Output is correct
35 Correct 5 ms 456 KB Output is correct
36 Correct 26 ms 1612 KB Output is correct
37 Correct 32 ms 1872 KB Output is correct
38 Correct 42 ms 2604 KB Output is correct
39 Correct 13 ms 1084 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 84 ms 2884 KB Output is correct
42 Correct 49 ms 3220 KB Output is correct
43 Correct 57 ms 2880 KB Output is correct
44 Correct 44 ms 3196 KB Output is correct
45 Correct 44 ms 3372 KB Output is correct
46 Correct 93 ms 3200 KB Output is correct
47 Correct 38 ms 3032 KB Output is correct
48 Correct 51 ms 3052 KB Output is correct
49 Correct 41 ms 2880 KB Output is correct
50 Correct 346 ms 3064 KB Output is correct
51 Correct 360 ms 3372 KB Output is correct
52 Correct 335 ms 3140 KB Output is correct
53 Correct 359 ms 3408 KB Output is correct
54 Correct 336 ms 3048 KB Output is correct
55 Correct 372 ms 3396 KB Output is correct
56 Correct 319 ms 3012 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 0 ms 204 KB Output is correct
5 Correct 1 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 28 ms 2204 KB Output is correct
10 Correct 8 ms 716 KB Output is correct
11 Correct 18 ms 1520 KB Output is correct
12 Correct 19 ms 1440 KB Output is correct
13 Correct 25 ms 1996 KB Output is correct
14 Correct 16 ms 1356 KB Output is correct
15 Correct 4 ms 460 KB Output is correct
16 Correct 16 ms 1360 KB Output is correct
17 Correct 41 ms 3056 KB Output is correct
18 Correct 22 ms 1868 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 12 ms 972 KB Output is correct
35 Correct 35 ms 2256 KB Output is correct
36 Correct 43 ms 2576 KB Output is correct
37 Correct 91 ms 2408 KB Output is correct
38 Correct 102 ms 2608 KB Output is correct
39 Correct 32 ms 2224 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 23 ms 1228 KB Output is correct
42 Correct 38 ms 2424 KB Output is correct
43 Correct 5 ms 456 KB Output is correct
44 Correct 26 ms 1612 KB Output is correct
45 Correct 32 ms 1872 KB Output is correct
46 Correct 42 ms 2604 KB Output is correct
47 Correct 13 ms 1084 KB Output is correct
48 Correct 2 ms 460 KB Output is correct
49 Correct 84 ms 2884 KB Output is correct
50 Correct 49 ms 3220 KB Output is correct
51 Correct 57 ms 2880 KB Output is correct
52 Correct 44 ms 3196 KB Output is correct
53 Correct 44 ms 3372 KB Output is correct
54 Correct 93 ms 3200 KB Output is correct
55 Correct 38 ms 3032 KB Output is correct
56 Correct 51 ms 3052 KB Output is correct
57 Correct 41 ms 2880 KB Output is correct
58 Correct 346 ms 3064 KB Output is correct
59 Correct 360 ms 3372 KB Output is correct
60 Correct 335 ms 3140 KB Output is correct
61 Correct 359 ms 3408 KB Output is correct
62 Correct 336 ms 3048 KB Output is correct
63 Correct 372 ms 3396 KB Output is correct
64 Correct 319 ms 3012 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Incorrect 1 ms 312 KB Output isn't correct
67 Halted 0 ms 0 KB -