Submission #878500

#TimeUsernameProblemLanguageResultExecution timeMemory
878500phoenix0423Maze (JOI23_ho_t3)C++17
19 / 100
2051 ms15656 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pll; #define fastio ios::sync_with_stdio(false), cin.tie(0) #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define pb push_back #define eb emplace_back #define f first #define s second const int INF = 1e9; struct pt{ int x, y; pt(){} pt(int _x, int _y) : x(_x), y(_y){} bool operator < (const pt& other) const{ return x < other.x; } }; istream &operator>> (istream &s, pt &p){ s >> p.x >> p.y; return s; } int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int main(void){ fastio; int r, c, n; cin>>r>>c>>n; pt st, ed; cin>>st>>ed; st.x--, st.y--, ed.x--, ed.y--; vector<string> s(r); REP(i, r) cin>>s[i]; vector<vector<int>> dist(r, vector<int>(c, INF)), in(r, vector<int>(c)); dist[st.x][st.y] = 0; typedef pair<int, pt> pipt; queue<pipt> q; q.push({0, st}); in[st.x][st.y] = 1; auto inbound = [&](int x, int y) -> bool{ return x >= 0 && y >= 0 && x < r && y < c; }; while(!q.empty()){ auto [dis, pos] = q.front(); q.pop(); auto [x, y] = pos; in[x][y] = 0; for(int d = 0; d < 4; d++){ int xx = x + dx[d], yy = y + dy[d]; if(!inbound(xx, yy) || s[xx][yy] == '#') continue; if(dist[xx][yy] > dist[x][y]){ dist[xx][yy] = dist[x][y]; if(!in[xx][yy]) in[xx][yy] = 1, q.push({dist[x][y], pt(xx, yy)}); } } for(int xx = x - n; xx <= x + n; xx++){ for(int yy = y - n; yy <= y + n; yy++){ if(!inbound(xx, yy)) continue; int tk = (xx == x - n) + (xx == x + n) + (yy == y - n) + (yy == y + n); if(tk == 2) continue; if(dist[xx][yy] > dist[x][y] + 1){ dist[xx][yy] = dist[x][y] + 1; if(!in[xx][yy]) in[xx][yy] = 1, q.push({dist[xx][yy], pt(xx, yy)}); } } } } cout<<dist[ed.x][ed.y]<<"\n"; }
#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...