제출 #917216

#제출 시각아이디문제언어결과실행 시간메모리
917216vaneaMecho (IOI09_mecho)C++14
95 / 100
157 ms8304 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mxN = 801; int n, s; vector<string> field(mxN); bool vis1[mxN][mxN], vis2[mxN][mxN]; int d1[mxN][mxN], d2[mxN][mxN]; vector<int> xy = {1, 0, -1, 0}, yx = {0, 1, 0, -1}; bool valid(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < n && (field[x][y] == 'G' || field[x][y] == 'M')); } void bfs1(queue<array<int, 2>> &q) { while(!q.empty()) { auto x = q.front()[0], y = q.front()[1]; q.pop(); for(int k = 0; k < 4; k++) { int a = x + xy[k], b = y + yx[k]; if(valid(a, b) && !vis1[a][b]) { vis1[a][b] = true; d1[a][b] = d1[x][y]+1; q.push({a, b}); } } } } bool reaches(int a, int b) { return a/s < b; } void bfs2(queue<array<int, 2>> &q, int t) { while(!q.empty()) { auto x = q.front()[0], y = q.front()[1]; q.pop(); for(int k = 0; k < 4; k++) { int a = x + xy[k], b = y + yx[k]; if(valid(a, b) && !vis2[a][b] && reaches(d2[x][y]+1, d1[a][b] - t)) { vis2[a][b] = true; d2[a][b] = d2[x][y] + 1; q.push({a, b}); } } } } void restart() { memset(vis2, false, sizeof vis2); memset(d2, 0, sizeof d2); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> s; vector<array<int, 2>> hives; array<int, 2> start, finish; for(int i = 0; i < n; i++) { cin >> field[i]; for(int j = 0; j < n; j++) { if(field[i][j] == 'M') { start = {i, j}; } else if(field[i][j] == 'H') { hives.push_back({i, j}); } else if(field[i][j] == 'D') { finish = {i, j}; } } } queue<array<int, 2>> q; for(auto it : hives) { q.push(it); vis1[it[0]][it[1]] = true; } bfs1(q); int l = 0, r = n*n; while(l <= r) { int mid = (l+r)/2; restart(); q.push(start); if(d1[start[0]][start[1]] <= mid) q.pop(); vis2[start[0]][start[1]] = true; bfs2(q, mid); bool can = false; for(int k = 0; k < 4; k++) { int a = finish[0] + xy[k], b = finish[1] + yx[k]; if(valid(a, b) && vis2[a][b]) { can = true; } } if(can) l = mid+1; else r = mid-1; } cout << l-1; }

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

mecho.cpp: In function 'int main()':
mecho.cpp:93:60: warning: 'finish.std::array<int, 2>::_M_elems[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   93 |             int a = finish[0] + xy[k], b = finish[1] + yx[k];
      |                                                            ^
mecho.cpp:93:37: warning: 'finish.std::array<int, 2>::_M_elems[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   93 |             int a = finish[0] + xy[k], b = finish[1] + yx[k];
      |                                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...