Submission #1218220

#TimeUsernameProblemLanguageResultExecution timeMemory
1218220InvMODMaze (JOI23_ho_t3)C++17
62 / 100
86 ms29784 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define eb emplace_back #define vi vector<int> #define pi pair<int,int> #define sz(v) (int)(v).size() #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) template<class T> using upq = priority_queue<T, vector<T>, greater<T>>; template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());} template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());} #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define ROF(i, a, b) for(int i = (a); i >= (b); i--) #define sumof(x) accumulate(all(x), 0ll) #define dbg(x) "[" << #x " = " << (x) << "]" #define el "\n" using ll = long long; using ld = long double; template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);} template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);} void Main() { int R,C, jump; cin >> R >> C >> jump; pi start; cin >> start.fi >> start.se; int ox, oy; cin >> ox >> oy; vector<vi> a(R + 1, vi(C + 1)); FOR(i, 1, R) FOR(j, 1, C){ char c; cin >> c; a[i][j] = (c == '#' ? 1 : 0); } const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; auto init = [&](int x, int y) -> bool{ return (0 < x && x <= R) && (0 < y && y <= C); }; // white -> expand with 0 distance // black -> expand until we can't and will increase the distance vector<vi> dist(R + 1, vi(C + 1, 0)); queue<pi> expand; queue<pair<pi, pi>> operation; expand.push(start); dist[start.fi][start.se] = 1; while(sz(expand)){ // find all nodes that are available while(sz(expand)){ pi e = expand.front(); expand.pop(); int x = e.fi, y = e.se; FOR(i, 0, 3){ int nx = x + dx[i]; int ny = y + dy[i]; if(init(nx, ny) && !dist[nx][ny]){ if(a[nx][ny]){ dist[nx][ny] = dist[x][y] + 1; operation.push({pi(nx, ny), pi(0, 0)}); } else{ dist[nx][ny] = dist[x][y]; expand.push(pi(nx, ny)); } } } } while(sz(operation)){ pair<pi, pi> e = operation.front(); operation.pop(); int x = e.fi.fi, y = e.fi.se, canx = e.se.fi, cany = e.se.se; if(canx == jump - 1 || cany == jump - 1) expand.emplace(x, y); FOR(i, 0, 3){ int nx = x + dx[i]; int ny = y + dy[i]; if(init(nx, ny) && !dist[nx][ny]){ if(canx + abs(dx[i]) >= jump || cany + abs(dy[i]) >= jump) continue; dist[nx][ny] = dist[x][y]; operation.push(make_pair(pi(nx, ny), pi(canx + abs(dx[i]), cany + abs(dy[i])))); } } } } cout << dist[ox][oy] - 1 << el; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout); } int t = 1; while(t--) Main(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:119:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:120:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...