답안 #455293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
455293 2021-08-05T18:49:27 Z dxz05 Mecho (IOI09_mecho) C++14
60 / 100
486 ms 44500 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 = 805*805;
const int M = 876;

vector<int> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
vector<int> g[N];

void bfs(vector<int> vec, vector<int> &d){
    fill(all(d), INF);
    queue<int> q;
    for (int x : vec){
        d[x] = 0;
        q.push(x);
    }

    while (!q.empty()){
        int x = q.front(); q.pop();
        for (int y : g[x]){
            if (d[y] == INF){
                d[y] = d[x] + 1;
                q.push(y);
            }
        }
    }
}


int p[N];

int find(int x){
    return (x == p[x] ? x : p[x] = find(p[x]));
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rng() & 1) swap(x, y);
    p[x] = y;
}

int DD = 0, MM = 0;

bool check(int val, vector<int> &d1, vector<int> &d2){
    int n = d1.size();

    for (int i = 0; i < n; i++) p[i] = i;

    for (int i = 0; i < n; i++){
        if (d1[i] + val >= d2[i] || d2[i] == INF) continue;
        for (int j : g[i]){
            if (d1[j] + val < d2[j] && d2[j] != INF) unite(i, j);
        }
    }

    return find(MM) == find(DD);
}

char a[M][M];
void solve(int TC) {
    int n, S;
    cin >> n >> S;

    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            cin >> a[i][j];
            if (a[i][j] == 'M') MM = i * n + j;
            if (a[i][j] == 'D') DD = i * n + j;
        }
    }

    vector<int> HH;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if (a[i][j] == 'H') HH.push_back(i * n + j);
            if (a[i][j] == 'T') continue;
            for (int it = 0; it < 4; it++){
                int x = i + dx[it], y = j + dy[it];
                if (x >= 0 && x < n && y >= 0 && y < n && a[x][y] != 'T'){
                    g[n * i + j].push_back(n * x + y);
                }
            }
        }
    }

    vector<int> d1(n * n), d2(n * n);
    bfs({MM}, d1);
    bfs(HH, d2);

    for (int &x : d1){
        if (x != INF) x = (x) / S;
    }

//    for (int i = 0; i < d1.size(); i++){
//        if (d1[i] == INF) cout << '#'; else
//            cout << d1[i];
//        if ((i + 1) % n == 0) cout << endl;
//    }
//    cout << endl;

//    for (int i = 0; i < d2.size(); i++){
//        if (d2[i] == INF) cout << '#'; else
//            cout << d2[i];
//        if ((i + 1) % n == 0) cout << endl;
//    }

    int l = 0, r = n * n;
    while (l <= r){
        int m = (l + r) >> 1;
        if (check(m, d1, d2)) l = m + 1; else
            r = m - 1;
    }

    cout << l - 1;

}

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

mecho.cpp: In function 'int main()':
mecho.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
mecho.cpp:173:9: note: in expansion of macro 'debug'
  173 |         debug(test);
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 15436 KB Output is correct
2 Incorrect 11 ms 15508 KB Output isn't correct
3 Correct 11 ms 15436 KB Output is correct
4 Incorrect 12 ms 15484 KB Output isn't correct
5 Correct 11 ms 15484 KB Output is correct
6 Incorrect 10 ms 15564 KB Output isn't correct
7 Incorrect 444 ms 44408 KB Output isn't correct
8 Correct 11 ms 15564 KB Output is correct
9 Correct 10 ms 15540 KB Output is correct
10 Correct 11 ms 15564 KB Output is correct
11 Correct 10 ms 15568 KB Output is correct
12 Incorrect 11 ms 15668 KB Output isn't correct
13 Correct 11 ms 15660 KB Output is correct
14 Correct 12 ms 15672 KB Output is correct
15 Correct 11 ms 15564 KB Output is correct
16 Correct 11 ms 15548 KB Output is correct
17 Correct 11 ms 15564 KB Output is correct
18 Correct 10 ms 15544 KB Output is correct
19 Correct 10 ms 15560 KB Output is correct
20 Correct 11 ms 15540 KB Output is correct
21 Correct 11 ms 15564 KB Output is correct
22 Correct 13 ms 15564 KB Output is correct
23 Correct 11 ms 15552 KB Output is correct
24 Correct 11 ms 15564 KB Output is correct
25 Correct 11 ms 15644 KB Output is correct
26 Correct 12 ms 15692 KB Output is correct
27 Correct 11 ms 15676 KB Output is correct
28 Correct 11 ms 15680 KB Output is correct
29 Correct 11 ms 15676 KB Output is correct
30 Correct 11 ms 15684 KB Output is correct
31 Correct 12 ms 15672 KB Output is correct
32 Correct 13 ms 15820 KB Output is correct
33 Correct 28 ms 19280 KB Output is correct
34 Correct 27 ms 19328 KB Output is correct
35 Incorrect 78 ms 20188 KB Output isn't correct
36 Correct 32 ms 20420 KB Output is correct
37 Correct 33 ms 20428 KB Output is correct
38 Incorrect 124 ms 21644 KB Output isn't correct
39 Correct 37 ms 21680 KB Output is correct
40 Correct 39 ms 21576 KB Output is correct
41 Incorrect 122 ms 23228 KB Output isn't correct
42 Correct 44 ms 23108 KB Output is correct
43 Correct 45 ms 22960 KB Output is correct
44 Incorrect 167 ms 25012 KB Output isn't correct
45 Correct 66 ms 24672 KB Output is correct
46 Correct 63 ms 24604 KB Output is correct
47 Incorrect 191 ms 26848 KB Output isn't correct
48 Correct 60 ms 26392 KB Output is correct
49 Correct 68 ms 26280 KB Output is correct
50 Incorrect 240 ms 28968 KB Output isn't correct
51 Correct 88 ms 28216 KB Output is correct
52 Correct 69 ms 28080 KB Output is correct
53 Incorrect 274 ms 31348 KB Output isn't correct
54 Correct 75 ms 30204 KB Output is correct
55 Correct 78 ms 29992 KB Output is correct
56 Incorrect 324 ms 33868 KB Output isn't correct
57 Correct 96 ms 32324 KB Output is correct
58 Correct 89 ms 32056 KB Output is correct
59 Incorrect 386 ms 36540 KB Output isn't correct
60 Correct 99 ms 34584 KB Output is correct
61 Correct 110 ms 34396 KB Output is correct
62 Incorrect 486 ms 39384 KB Output isn't correct
63 Correct 356 ms 36220 KB Output is correct
64 Correct 428 ms 36264 KB Output is correct
65 Correct 422 ms 36344 KB Output is correct
66 Correct 368 ms 36336 KB Output is correct
67 Correct 329 ms 36332 KB Output is correct
68 Correct 255 ms 36364 KB Output is correct
69 Correct 310 ms 36360 KB Output is correct
70 Correct 223 ms 36380 KB Output is correct
71 Correct 215 ms 36292 KB Output is correct
72 Correct 200 ms 36252 KB Output is correct
73 Correct 413 ms 44420 KB Output is correct
74 Correct 365 ms 44356 KB Output is correct
75 Correct 403 ms 44392 KB Output is correct
76 Correct 365 ms 44336 KB Output is correct
77 Correct 375 ms 44300 KB Output is correct
78 Correct 376 ms 44368 KB Output is correct
79 Correct 331 ms 44292 KB Output is correct
80 Correct 335 ms 44372 KB Output is correct
81 Correct 351 ms 44484 KB Output is correct
82 Correct 335 ms 44500 KB Output is correct
83 Correct 399 ms 44192 KB Output is correct
84 Correct 404 ms 44404 KB Output is correct
85 Correct 401 ms 44196 KB Output is correct
86 Correct 414 ms 44224 KB Output is correct
87 Correct 397 ms 44416 KB Output is correct
88 Correct 401 ms 44416 KB Output is correct
89 Correct 421 ms 44380 KB Output is correct
90 Correct 430 ms 44396 KB Output is correct
91 Correct 410 ms 44228 KB Output is correct
92 Correct 426 ms 44324 KB Output is correct