Submission #803126

# Submission time Handle Problem Language Result Execution time Memory
803126 2023-08-02T22:53:20 Z Liudas Mecho (IOI09_mecho) C++17
84 / 100
247 ms 5232 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int N, S;
    cin >> N >> S;
    vector<string> _map(N + 2);
    string t = string(N+2, 'T');
    _map[0] = t;
    _map[N+1] = t;
    for(int i = 1; i <= N; i ++){
        cin >> _map[i];
        _map[i] = "T"+_map[i] + "T";
    }
    int sx, sy, ex, ey;
    vector<pair<int, int>> bees;
    for(int i = 1; i <= N;  i++){
        for(int j = 1; j <= N; j ++){
            if(_map[i][j] == 'M'){
                sx = j;
                sy = i;
                _map[i][j]='G';
            }
            if(_map[i][j] == 'D'){
                ex = j;
                ey = i;
            }
            if(_map[i][j] == 'H'){
                _map[i][j] == 'T';
                bees.push_back({i, j});
            }
        }
    }
    vector<int> dx = {1,-1,0,0}, dy = {0,0,1,-1};
    int l = 0, r = N * N + 10;
    while(l + 1 < r){
        int mid = (l + r) / 2;
        //cout << mid << " " << l << " " << r << endl;
        vector<string> arr = _map;
        vector<vector<int>> been(N + 2, vector<int>(N + 2));
        queue<pair<int, int>> bee, bee2, moves;
        moves.push({sy, sx});
        for(auto[l, r] : bees){
            bee.push({l, r});
        }
        bool reach = false;
        for(int j = 0; j < mid; j ++){
            while(!bee.empty()){
                int a = bee.front().first, b = bee.front().second;
                bee.pop();
                for(int i = 0; i < 4; i ++){
                    if(arr[a+dy[i]][b+dx[i]] == 'G'){
                        arr[a+dy[i]][b+dx[i]] = 'T';
                        bee2.push({a+dy[i], b+dx[i]});
                    }
                }
            }
            swap(bee, bee2);
        }
        int it = 0;
        while(!moves.empty() && !reach){
            while(!moves.empty()){
                int a = moves.front().first, b = moves.front().second;
                //cout << a << " " << b << " " << mid << endl;
                if(been[a][b] >= (it + 1) * S)break;
                if(arr[a][b]=='D'){reach = true;break;}
                moves.pop();
                //cout << arr[a][b] << endl;
                if(arr[a][b] == 'T')continue;
                for(int i = 0; i < 4; i ++){
                   // cout << a + dy[i] << " " << endl;
                    if(!been[a+dy[i]][b+dx[i]] && arr[a+dy[i]][b+dx[i]] != 'T'){
                        been[a+dy[i]][b+dx[i]] = been[a][b] + 1;
                        moves.push({a+dy[i], b+dx[i]});
                    }
                }
            }
            //cout << " ?" << endl;
            while(!bee.empty()){
                int a = bee.front().first, b = bee.front().second;
                bee.pop();
                for(int i = 0; i < 4; i ++){
                    if(arr[a+dy[i]][b+dx[i]] == 'G'){
                        arr[a+dy[i]][b+dx[i]] = 'T';
                        bee2.push({a+dy[i], b+dx[i]});
                    }
                }
            }
            swap(bee, bee2);
            it++;
        }
        if(reach){
            l = mid;
        }
        else{
            r = mid;
        }
    }
    cout << l << endl;
    return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:31:28: warning: value computed is not used [-Wunused-value]
   31 |                 _map[i][j] == 'T';
mecho.cpp:17:17: warning: variable 'ex' set but not used [-Wunused-but-set-variable]
   17 |     int sx, sy, ex, ey;
      |                 ^~
mecho.cpp:17:21: warning: variable 'ey' set but not used [-Wunused-but-set-variable]
   17 |     int sx, sy, ex, ey;
      |                     ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 200 ms 4908 KB Output is correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 224 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 19 ms 1108 KB Output is correct
34 Correct 22 ms 1192 KB Output is correct
35 Correct 24 ms 1164 KB Output is correct
36 Correct 25 ms 1364 KB Output is correct
37 Correct 22 ms 1392 KB Output is correct
38 Correct 32 ms 1456 KB Output is correct
39 Correct 33 ms 1660 KB Output is correct
40 Correct 29 ms 1748 KB Output is correct
41 Correct 48 ms 1740 KB Output is correct
42 Correct 41 ms 2004 KB Output is correct
43 Correct 36 ms 2004 KB Output is correct
44 Correct 54 ms 2092 KB Output is correct
45 Correct 57 ms 2460 KB Output is correct
46 Correct 43 ms 2388 KB Output is correct
47 Correct 65 ms 2452 KB Output is correct
48 Correct 58 ms 2840 KB Output is correct
49 Correct 51 ms 2772 KB Output is correct
50 Correct 79 ms 2848 KB Output is correct
51 Correct 84 ms 3320 KB Output is correct
52 Correct 59 ms 3284 KB Output is correct
53 Correct 112 ms 3284 KB Output is correct
54 Correct 96 ms 3748 KB Output is correct
55 Correct 76 ms 3764 KB Output is correct
56 Correct 116 ms 3760 KB Output is correct
57 Correct 102 ms 4296 KB Output is correct
58 Correct 90 ms 4296 KB Output is correct
59 Correct 126 ms 4272 KB Output is correct
60 Correct 140 ms 4792 KB Output is correct
61 Correct 119 ms 4916 KB Output is correct
62 Correct 156 ms 4808 KB Output is correct
63 Correct 180 ms 4808 KB Output is correct
64 Correct 247 ms 4788 KB Output is correct
65 Correct 204 ms 4800 KB Output is correct
66 Correct 208 ms 4788 KB Output is correct
67 Incorrect 203 ms 4808 KB Output isn't correct
68 Correct 182 ms 4820 KB Output is correct
69 Correct 157 ms 4844 KB Output is correct
70 Correct 183 ms 4736 KB Output is correct
71 Correct 178 ms 4820 KB Output is correct
72 Correct 200 ms 4824 KB Output is correct
73 Correct 167 ms 5120 KB Output is correct
74 Correct 213 ms 5100 KB Output is correct
75 Correct 241 ms 5232 KB Output is correct
76 Correct 229 ms 5104 KB Output is correct
77 Correct 224 ms 5096 KB Output is correct
78 Incorrect 212 ms 5076 KB Output isn't correct
79 Correct 193 ms 5052 KB Output is correct
80 Correct 200 ms 5076 KB Output is correct
81 Correct 207 ms 5132 KB Output is correct
82 Correct 194 ms 5072 KB Output is correct
83 Correct 196 ms 5052 KB Output is correct
84 Correct 216 ms 5032 KB Output is correct
85 Correct 206 ms 5036 KB Output is correct
86 Correct 243 ms 5000 KB Output is correct
87 Correct 204 ms 5204 KB Output is correct
88 Correct 197 ms 5096 KB Output is correct
89 Correct 210 ms 4964 KB Output is correct
90 Correct 236 ms 4984 KB Output is correct
91 Correct 196 ms 4980 KB Output is correct
92 Correct 198 ms 4976 KB Output is correct