제출 #803129

#제출 시각아이디문제언어결과실행 시간메모리
803129LiudasMecho (IOI09_mecho)C++17
100 / 100
239 ms5216 KiB
#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 = -1, r = N * N + 10; bool gr = false; 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;gr = 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; }

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

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;
      |                     ^~
mecho.cpp:38:10: warning: variable 'gr' set but not used [-Wunused-but-set-variable]
   38 |     bool gr = false;
      |          ^~
#Verdict Execution timeMemoryGrader output
Fetching results...