답안 #455290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
455290 2021-08-05T18:47:36 Z dxz05 Mecho (IOI09_mecho) C++14
0 / 100
45 ms 65540 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 = 5e6 + 3e2;
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 'void solve(int)':
mecho.cpp:139:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |     for (int i = 0; i < d2.size(); i++){
      |                     ~~^~~~~~~~~~~
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 Runtime error 40 ms 65540 KB Execution killed with signal 9
2 Runtime error 40 ms 65540 KB Execution killed with signal 9
3 Runtime error 39 ms 65540 KB Execution killed with signal 9
4 Runtime error 39 ms 65540 KB Execution killed with signal 9
5 Runtime error 39 ms 65540 KB Execution killed with signal 9
6 Runtime error 38 ms 65540 KB Execution killed with signal 9
7 Runtime error 40 ms 65540 KB Execution killed with signal 9
8 Runtime error 39 ms 65540 KB Execution killed with signal 9
9 Runtime error 40 ms 65540 KB Execution killed with signal 9
10 Runtime error 45 ms 65540 KB Execution killed with signal 9
11 Runtime error 40 ms 65540 KB Execution killed with signal 9
12 Runtime error 37 ms 65540 KB Execution killed with signal 9
13 Runtime error 43 ms 65540 KB Execution killed with signal 9
14 Runtime error 37 ms 65540 KB Execution killed with signal 9
15 Runtime error 38 ms 65540 KB Execution killed with signal 9
16 Runtime error 39 ms 65540 KB Execution killed with signal 9
17 Runtime error 39 ms 65540 KB Execution killed with signal 9
18 Runtime error 38 ms 65540 KB Execution killed with signal 9
19 Runtime error 39 ms 65540 KB Execution killed with signal 9
20 Runtime error 39 ms 65540 KB Execution killed with signal 9
21 Runtime error 39 ms 65540 KB Execution killed with signal 9
22 Runtime error 39 ms 65540 KB Execution killed with signal 9
23 Runtime error 43 ms 65540 KB Execution killed with signal 9
24 Runtime error 36 ms 65540 KB Execution killed with signal 9
25 Runtime error 45 ms 65540 KB Execution killed with signal 9
26 Runtime error 39 ms 65540 KB Execution killed with signal 9
27 Runtime error 39 ms 65540 KB Execution killed with signal 9
28 Runtime error 36 ms 65540 KB Execution killed with signal 9
29 Runtime error 41 ms 65540 KB Execution killed with signal 9
30 Runtime error 43 ms 65536 KB Execution killed with signal 9
31 Runtime error 39 ms 65540 KB Execution killed with signal 9
32 Runtime error 41 ms 65540 KB Execution killed with signal 9
33 Runtime error 39 ms 65540 KB Execution killed with signal 9
34 Runtime error 40 ms 65540 KB Execution killed with signal 9
35 Runtime error 40 ms 65540 KB Execution killed with signal 9
36 Runtime error 41 ms 65540 KB Execution killed with signal 9
37 Runtime error 40 ms 65540 KB Execution killed with signal 9
38 Runtime error 38 ms 65540 KB Execution killed with signal 9
39 Runtime error 39 ms 65540 KB Execution killed with signal 9
40 Runtime error 40 ms 65540 KB Execution killed with signal 9
41 Runtime error 39 ms 65540 KB Execution killed with signal 9
42 Runtime error 39 ms 65540 KB Execution killed with signal 9
43 Runtime error 39 ms 65540 KB Execution killed with signal 9
44 Runtime error 39 ms 65540 KB Execution killed with signal 9
45 Runtime error 39 ms 65540 KB Execution killed with signal 9
46 Runtime error 39 ms 65540 KB Execution killed with signal 9
47 Runtime error 41 ms 65540 KB Execution killed with signal 9
48 Runtime error 38 ms 65540 KB Execution killed with signal 9
49 Runtime error 40 ms 65540 KB Execution killed with signal 9
50 Runtime error 41 ms 65540 KB Execution killed with signal 9
51 Runtime error 39 ms 65540 KB Execution killed with signal 9
52 Runtime error 42 ms 65536 KB Execution killed with signal 9
53 Runtime error 38 ms 65540 KB Execution killed with signal 9
54 Runtime error 43 ms 65540 KB Execution killed with signal 9
55 Runtime error 39 ms 65540 KB Execution killed with signal 9
56 Runtime error 40 ms 65540 KB Execution killed with signal 9
57 Runtime error 40 ms 65540 KB Execution killed with signal 9
58 Runtime error 41 ms 65540 KB Execution killed with signal 9
59 Runtime error 39 ms 65540 KB Execution killed with signal 9
60 Runtime error 42 ms 65540 KB Execution killed with signal 9
61 Runtime error 40 ms 65540 KB Execution killed with signal 9
62 Runtime error 45 ms 65540 KB Execution killed with signal 9
63 Runtime error 42 ms 65540 KB Execution killed with signal 9
64 Runtime error 41 ms 65540 KB Execution killed with signal 9
65 Runtime error 39 ms 65540 KB Execution killed with signal 9
66 Runtime error 40 ms 65540 KB Execution killed with signal 9
67 Runtime error 38 ms 65540 KB Execution killed with signal 9
68 Runtime error 41 ms 65540 KB Execution killed with signal 9
69 Runtime error 40 ms 65540 KB Execution killed with signal 9
70 Runtime error 39 ms 65540 KB Execution killed with signal 9
71 Runtime error 40 ms 65540 KB Execution killed with signal 9
72 Runtime error 38 ms 65540 KB Execution killed with signal 9
73 Runtime error 41 ms 65540 KB Execution killed with signal 9
74 Runtime error 40 ms 65540 KB Execution killed with signal 9
75 Runtime error 36 ms 65540 KB Execution killed with signal 9
76 Runtime error 40 ms 65540 KB Execution killed with signal 9
77 Runtime error 39 ms 65540 KB Execution killed with signal 9
78 Runtime error 39 ms 65540 KB Execution killed with signal 9
79 Runtime error 39 ms 65540 KB Execution killed with signal 9
80 Runtime error 39 ms 65540 KB Execution killed with signal 9
81 Runtime error 38 ms 65540 KB Execution killed with signal 9
82 Runtime error 38 ms 65540 KB Execution killed with signal 9
83 Runtime error 40 ms 65540 KB Execution killed with signal 9
84 Runtime error 41 ms 65536 KB Execution killed with signal 9
85 Runtime error 36 ms 65540 KB Execution killed with signal 9
86 Runtime error 39 ms 65540 KB Execution killed with signal 9
87 Runtime error 39 ms 65540 KB Execution killed with signal 9
88 Runtime error 39 ms 65540 KB Execution killed with signal 9
89 Runtime error 36 ms 65540 KB Execution killed with signal 9
90 Runtime error 40 ms 65540 KB Execution killed with signal 9
91 Runtime error 39 ms 65540 KB Execution killed with signal 9
92 Runtime error 40 ms 65540 KB Execution killed with signal 9