제출 #1123402

#제출 시각아이디문제언어결과실행 시간메모리
1123402Neco_arcMaze (JOI23_ho_t3)C++20
100 / 100
438 ms112028 KiB
#include<bits/stdc++.h> using i64 = long long; using namespace std; #define all(datastructure) datastructure.begin(),datastructure.end() #define find(_vector , _data) upper_bound(_vector.begin(),_vector.end(),_data) - _vector.begin() int numrow , numcol , k; int sourcex , sourcey; int sinkx , sinky; struct _D { int x , y; int stepx , stepy; }; queue<_D> freezone , banzone; const int dx[] = {-1 , 0, 1, 0}; const int dy[] = {0 , 1 , 0 , -1}; bool Zone(int x , int y) { return x > 0 && x <= numrow && y > 0 && y <= numcol; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> numrow >> numcol >> k; cin >> sourcex >> sourcey; cin >> sinkx >> sinky; vector<vector<char>> a(numrow+2,vector<char>(numcol+2)); vector<vector<int>> d(numrow+2,vector<int>(numcol+2,-1)); for (int i = 1; i <= numrow; ++i) for (int j = 1; j <= numcol; ++j) cin >> a[i][j]; if (a[sourcex][sourcey] == '.') { d[sourcex][sourcey] = 0; freezone.push({sourcex,sourcey,0,0}); } else { d[sourcex][sourcey] = 1; banzone.push({sourcex,sourcey,k-1,k-1}); } while (freezone.size() || banzone.size()) { while (banzone.size()) { _D node = banzone.front(); banzone.pop(); if (node.stepx == 0 || node.stepy == 0) freezone.push({node.x,node.y,0,0}); for (int i = 0; i < 4; ++i) { int u = node.x + dx[i]; int v = node.y + dy[i]; int remx = node.stepx - abs(dx[i]); int remy = node.stepy - abs(dy[i]); if ((remx>=0&&remy>=0) && Zone(u,v) && d[u][v] == -1) { d[u][v] = d[node.x][node.y]; banzone.push({u , v , remx , remy}); } } } while (freezone.size()) { _D node = freezone.front(); freezone.pop(); for (int i = 0; i < 4; ++i) { int u = node.x + dx[i]; int v = node.y + dy[i]; if (Zone(u,v) && d[u][v] == -1) { if (a[u][v] == '#') { banzone.push({u , v , k - 1 , k - 1}); d[u][v] = d[node.x][node.y] + 1; } else { freezone.push({u , v , 0 , 0}); d[u][v] = d[node.x][node.y]; } } } } } cout << d[sinkx][sinky]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...