제출 #455293

#제출 시각아이디문제언어결과실행 시간메모리
455293dxz05Mecho (IOI09_mecho)C++14
60 / 100
486 ms44500 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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);
      |         ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...