답안 #1019495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019495 2024-07-11T00:26:29 Z lucascgar Mecho (IOI09_mecho) C++17
84 / 100
123 ms 7096 KB
#include <bits/stdc++.h>

// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using namespace std;

/*
precalcula p grid o tempo que cada célula leva até ser ocupada por abelhas
binary search no tempo
p verificar se tempo x é válido:
floodfill do mecho começando no tempo x e ignorando s:
    continuar só se (dist[i][j]+s-1)/s + x < bee[i][j] ou se (dist[i][j]+s-1)/s + x == bee[i][j] e se nn for o último movimento, = dist[i][j]%s != 0
*/

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // overclock random

typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, double> pdd;

const int MAXN = 800+10;

bool g[MAXN][MAXN];
int bs[MAXN][MAXN]; // bs=bees

int d[MAXN][MAXN]; // distance (mecho)
int aux[4] = {1, -1, 0, 0};
signed main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // freopen("test.in", "r", stdin);
    // freopen("test.out", "w", stdout);
    // cout << fixed << setprecision(12);

    int n, s;
    cin >> n >> s;
    char x;
    pii st = {0,0}, en = {0,0};
    queue<pii> bq;
    for (int i=1;i<=n;i++) for (int j=1;j<=n;j++){
        cin >> x;
        g[i][j] = (x=='G' || x=='M');
        bs[i][j] = 1e9;

        if (x=='H'){
            bq.emplace(i,j);
            bs[i][j] = 0;
        }
        else if (x =='M') st = {i,j};
        else if (x == 'D') en = {i, j};


    }

    while (!bq.empty()){
        pii u = bq.front();
        bq.pop();

        int nd = bs[u.first][u.second]+1;

        for (int a=0,b=3;a<4;a++,b--){
            int ni = u.first+aux[a], nj = u.second+aux[b];

            if (bs[ni][nj] == 1e9 && g[ni][nj]){
                bs[ni][nj] = nd;
                bq.emplace(ni, nj);
            }

        }

    }

    g[en.first][en.second] = g[st.first][st.second] = 1;
    bool tru = 0;
    int in = 0, fi = 1e9, me;
    while (in<=fi){
        me = (in+fi)/2;
        for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) d[i][j] = 1e9;

        d[st.first][st.second] = 0;
        queue<pii> mq;
        mq.push(st);

        while (!mq.empty()){
            pii u = mq.front();
            mq.pop();
            int nd = d[u.first][u.second]+1;

            for (int a=0,b=3;a<4;a++,b--){
                int ni = u.first+aux[a], nj = u.second+aux[b];
                if (!g[ni][nj] || d[ni][nj] != 1e9) continue;

                if (me + (nd+s-1)/s < bs[ni][nj] || (me + (nd+s-1)/s == bs[ni][nj] && nd%s != 0)){
                    d[ni][nj] = nd;
                    mq.emplace(ni, nj);
                }

            }
        }

        if (d[en.first][en.second] != 1e9){
            tru=1, in = me+1;
        }else fi = me-1;

    }



    if (!tru) cout << "-1\n";

    else cout << in-1 << "\n"; 

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 51 ms 6692 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 1 ms 720 KB Output isn't correct
13 Incorrect 0 ms 604 KB Output isn't correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 716 KB Output is correct
22 Correct 0 ms 860 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 860 KB Output is correct
26 Correct 1 ms 856 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 0 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 1112 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 5 ms 2908 KB Output is correct
34 Correct 5 ms 2908 KB Output is correct
35 Correct 13 ms 2908 KB Output is correct
36 Correct 9 ms 3420 KB Output is correct
37 Correct 7 ms 3420 KB Output is correct
38 Correct 15 ms 3492 KB Output is correct
39 Correct 8 ms 3648 KB Output is correct
40 Correct 7 ms 3676 KB Output is correct
41 Correct 25 ms 3676 KB Output is correct
42 Correct 8 ms 4056 KB Output is correct
43 Correct 8 ms 4180 KB Output is correct
44 Correct 35 ms 4184 KB Output is correct
45 Correct 10 ms 4440 KB Output is correct
46 Correct 11 ms 4444 KB Output is correct
47 Correct 33 ms 4572 KB Output is correct
48 Correct 13 ms 5080 KB Output is correct
49 Correct 12 ms 4956 KB Output is correct
50 Correct 45 ms 5108 KB Output is correct
51 Correct 13 ms 5288 KB Output is correct
52 Correct 14 ms 5376 KB Output is correct
53 Correct 45 ms 5532 KB Output is correct
54 Correct 19 ms 5724 KB Output is correct
55 Correct 18 ms 5724 KB Output is correct
56 Correct 60 ms 5852 KB Output is correct
57 Correct 17 ms 6232 KB Output is correct
58 Correct 19 ms 6236 KB Output is correct
59 Correct 63 ms 6236 KB Output is correct
60 Correct 18 ms 6744 KB Output is correct
61 Correct 19 ms 6748 KB Output is correct
62 Correct 70 ms 6748 KB Output is correct
63 Correct 77 ms 6724 KB Output is correct
64 Correct 123 ms 6780 KB Output is correct
65 Correct 119 ms 6780 KB Output is correct
66 Correct 87 ms 6784 KB Output is correct
67 Correct 80 ms 6784 KB Output is correct
68 Correct 45 ms 6740 KB Output is correct
69 Correct 44 ms 6736 KB Output is correct
70 Correct 35 ms 6736 KB Output is correct
71 Correct 38 ms 6748 KB Output is correct
72 Incorrect 34 ms 6744 KB Output isn't correct
73 Incorrect 26 ms 7076 KB Output isn't correct
74 Correct 40 ms 7096 KB Output is correct
75 Correct 44 ms 7004 KB Output is correct
76 Correct 39 ms 6900 KB Output is correct
77 Correct 39 ms 6992 KB Output is correct
78 Correct 46 ms 7004 KB Output is correct
79 Correct 37 ms 7004 KB Output is correct
80 Correct 41 ms 6860 KB Output is correct
81 Correct 47 ms 7004 KB Output is correct
82 Correct 38 ms 6808 KB Output is correct
83 Correct 47 ms 7000 KB Output is correct
84 Correct 45 ms 6780 KB Output is correct
85 Correct 46 ms 7000 KB Output is correct
86 Correct 49 ms 6848 KB Output is correct
87 Correct 48 ms 7000 KB Output is correct
88 Correct 51 ms 6748 KB Output is correct
89 Correct 52 ms 6744 KB Output is correct
90 Correct 53 ms 6748 KB Output is correct
91 Correct 48 ms 6740 KB Output is correct
92 Correct 48 ms 6944 KB Output is correct