Submission #736323

#TimeUsernameProblemLanguageResultExecution timeMemory
736323CookieMaze (JOI23_ho_t3)C++14
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; ifstream fin("WINTER.inp"); ofstream fout("WINTER.out"); #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const ld PI = 3.14159265359; const int x[4] = {1, -1, 0, 0}; const int y[4] = {0, 0, 1, -1}; const ll mod = 1e9 + 7; const int mxn = 5e5, mxm = 1e5, sq = 400; const int base = (1 << 18); const ll inf = 1e9; const ld pre = 1e-6; int r, c, n, sti, stj, eni, enj; vt<vt<char>>a; vt<vt<int>>d; vt<int>lrow, rrow, lcol, rcol; bool inside(int i, int j){ return(i >= 1 && j >= 1 && i <= r && j <= c); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> r >> c >> n; a.resize(r + 1, vt<char>(c + 1)); d.resize(r + 1, vt<int>(c + 1)); lrow.resize(r + 1); rrow.resize(r + 1); lcol.resize(c + 1); rcol.resize(c + 1); cin >> sti >> stj >> eni >> enj; forr(i, 1, r + 1){ lrow[i] = c; rrow[i] = 1; forr(j, 1, c + 1){ lcol[j] = r; rcol[j] = 1; cin >> a[i][j]; d[i][j] = 1e9; } } deque<pair<int, int>>dq; dq.pb({sti, stj}); d[sti][stj] = 0; while(!dq.empty()){ auto [i, j] = dq.front(); dq.pop_front(); if(a[i][j] == '.'){ for(int t = 0; t < 4; t++){ int nwi = i + x[t], nwj = j + y[t]; if(inside(nwi, nwj)){ if(d[nwi][nwj] > d[i][j]){ d[nwi][nwj] = d[i][j]; dq.push_front({nwi, nwj}); } } } } for(auto ii: {i - n, i + n}){ if(!inside(ii, 1))continue; int le = max(1, j - n + 1), ri = min(c, j + n - 1); if(lrow[ii] <= le)le = max(le, rrow[ii]); if(rrow[ii] >= ri)ri = min(ri, lrow[ii]); for(int jj = le; jj <= ri; jj++){ if(d[ii][jj] > d[i][j] + 1){ d[ii][jj] = d[i][j] + 1; dq.push_back({ii, jj}); } } lrow[ii] = min(le, lrow[ii]); rrow[ii] = max(rrow[ii], ri); } for(auto jj : {j - n, j + n}){ if(!inside(1, jj))continue; int le = max(1, i - n + 1), ri = min(r, i + n - 1); if(lcol[jj] <= le)le = max(le, rcol[jj]); if(rcol[jj] >= ri)ri = min(ri, lcol[jj]); for(int ii = le; ii <= ri; ii++){ if(d[ii][jj] > d[i][j] + 1){ d[ii][jj] = d[i][j] + 1; dq.push_back({ii, jj}); } } lcol[jj] = min(le, lcol[jj]); rcol[jj] = max(rcol[jj], ri); } } int ans = 1e9; for(int i = eni - n + 1; i <= eni + n - 1; i++){ for(int j = enj - n + 1; j <= enj + n - 1; j++){ if(inside(i, j)){ ans = min(ans, d[i][j] + 1); } } } ans = min(ans, d[eni][enj]); cout << ans << "\n"; return(0); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:50:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |         auto [i, j] = dq.front(); dq.pop_front();
      |              ^
#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...