Submission #803125

# Submission time Handle Problem Language Result Execution time Memory
803125 2023-08-02T22:49:25 Z Liudas Mecho (IOI09_mecho) C++17
45 / 100
267 ms 5136 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 Incorrect 1 ms 212 KB Output isn't correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 199 ms 4912 KB Output is correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 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 Incorrect 1 ms 220 KB Output isn't correct
16 Correct 0 ms 212 KB Output is correct
17 Incorrect 0 ms 212 KB Output isn't correct
18 Correct 1 ms 212 KB Output is correct
19 Incorrect 0 ms 212 KB Output isn't correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Correct 1 ms 212 KB Output is correct
23 Incorrect 1 ms 212 KB Output isn't correct
24 Correct 1 ms 212 KB Output is correct
25 Incorrect 1 ms 212 KB Output isn't correct
26 Correct 1 ms 296 KB Output is correct
27 Incorrect 1 ms 212 KB Output isn't correct
28 Correct 1 ms 340 KB Output is correct
29 Incorrect 1 ms 340 KB Output isn't correct
30 Correct 1 ms 340 KB Output is correct
31 Incorrect 1 ms 340 KB Output isn't correct
32 Correct 1 ms 340 KB Output is correct
33 Incorrect 19 ms 1192 KB Output isn't correct
34 Correct 17 ms 1108 KB Output is correct
35 Correct 24 ms 1200 KB Output is correct
36 Incorrect 26 ms 1364 KB Output isn't correct
37 Correct 26 ms 1452 KB Output is correct
38 Correct 33 ms 1364 KB Output is correct
39 Incorrect 33 ms 1748 KB Output isn't correct
40 Correct 34 ms 1756 KB Output is correct
41 Correct 58 ms 1756 KB Output is correct
42 Incorrect 44 ms 2004 KB Output isn't correct
43 Correct 40 ms 2004 KB Output is correct
44 Correct 55 ms 2004 KB Output is correct
45 Incorrect 48 ms 2388 KB Output isn't correct
46 Correct 43 ms 2464 KB Output is correct
47 Correct 64 ms 2464 KB Output is correct
48 Incorrect 67 ms 2844 KB Output isn't correct
49 Correct 51 ms 2772 KB Output is correct
50 Correct 77 ms 2868 KB Output is correct
51 Incorrect 81 ms 3328 KB Output isn't correct
52 Correct 59 ms 3280 KB Output is correct
53 Correct 105 ms 3284 KB Output is correct
54 Incorrect 95 ms 3668 KB Output isn't correct
55 Correct 81 ms 3748 KB Output is correct
56 Correct 120 ms 3668 KB Output is correct
57 Incorrect 102 ms 4292 KB Output isn't correct
58 Correct 94 ms 4276 KB Output is correct
59 Correct 125 ms 4180 KB Output is correct
60 Incorrect 124 ms 4800 KB Output isn't correct
61 Correct 107 ms 4796 KB Output is correct
62 Correct 146 ms 4800 KB Output is correct
63 Correct 187 ms 4812 KB Output is correct
64 Correct 227 ms 4808 KB Output is correct
65 Correct 199 ms 4808 KB Output is correct
66 Incorrect 215 ms 4816 KB Output isn't correct
67 Incorrect 231 ms 4804 KB Output isn't correct
68 Correct 182 ms 4820 KB Output is correct
69 Correct 158 ms 4836 KB Output is correct
70 Correct 202 ms 4848 KB Output is correct
71 Correct 183 ms 4820 KB Output is correct
72 Correct 193 ms 4824 KB Output is correct
73 Correct 169 ms 5136 KB Output is correct
74 Correct 234 ms 5124 KB Output is correct
75 Correct 225 ms 5112 KB Output is correct
76 Correct 223 ms 5124 KB Output is correct
77 Correct 267 ms 5104 KB Output is correct
78 Incorrect 196 ms 5068 KB Output isn't correct
79 Correct 191 ms 5124 KB Output is correct
80 Correct 207 ms 5112 KB Output is correct
81 Correct 224 ms 5072 KB Output is correct
82 Correct 194 ms 5064 KB Output is correct
83 Correct 211 ms 5068 KB Output is correct
84 Correct 205 ms 5044 KB Output is correct
85 Correct 211 ms 5036 KB Output is correct
86 Correct 218 ms 5076 KB Output is correct
87 Correct 209 ms 5032 KB Output is correct
88 Correct 195 ms 4984 KB Output is correct
89 Correct 211 ms 4964 KB Output is correct
90 Correct 240 ms 4968 KB Output is correct
91 Correct 196 ms 4968 KB Output is correct
92 Correct 208 ms 4964 KB Output is correct