제출 #986000

#제출 시각아이디문제언어결과실행 시간메모리
986000VinhLuuMaze (JOI23_ho_t3)C++17
8 / 100
414 ms323608 KiB
//#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> //#define int long long //#define ll long long #define fi first #define se second #define pb push_back #define all(lmao) lmao.begin(), lmao.end() using namespace std; typedef pair<int,int> pii; typedef tuple<int,int,int> tp; const int N = 3e6 + 5; const int oo = 1e9 + 1; const int mod = 1e9 + 7; int block = 316; //const ll oo = 5e18; const int ha[4] = {1, -1, 0, 0}; const int co[4] = {0, 0, 1, -1}; const int tx[4] = {1, 1, -1, -1}; const int ty[4] = {1, -1, -1, 1}; int m, n, k, xt, yt, xs, ys; vector<int> f[N], a[N], ph[N], pc[N]; bool kt(int x,int y){ return x >= 1 && x <= m && y >= 1 && y <= n; } int row(int u,int v){ // cerr << u << " " << v << " t\n"; return (ph[u][v] == v ? v : ph[u][v] = row(u, ph[u][v])); } int col(int u,int v){ // cerr << u << " " << v << " " << pc[u][v] << " w\n"; // if(pc[u][v] == u) return u; return (pc[u][v] == u ? u : pc[u][v] = col(pc[u][v], v)); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> m >> n >> k; cin >> xs >> ys >> xt >> yt; for(int i = 1; i <= m; i ++){ string s; cin >> s; f[i].pb(oo); a[i].pb(0); ph[i].pb(0); pc[i].pb(0); for(int j = 0; j < n; j ++){ f[i].pb(oo); pc[i].pb(0); ph[i].pb(j + 1); if(s[j] == '.') a[i].pb(0); else a[i].pb(1); } f[i].pb(oo); a[i].pb(0); ph[i].pb(0); pc[i].pb(0); } for(int i = 1; i <= n + 1; i ++) pc[0].pb(0); for(int i = 1; i <= n; i ++){ for(int j = 1; j <= m; j ++){ pc[j][i] = j; } } priority_queue<tp, vector<tp>, greater<tp>> q; f[xs][ys] = 0; q.push({0, xs, ys}); int ans = oo; while(!q.empty()){ int val, x, y; tie(val, x, y) = q.top(); // int x = q.front().fi; // int y = q.front().se; // cerr << x << " " << y << " y\n"; q.pop(); if(val > f[x][y]) continue; if(x == xt && y == yt) ans = min(ans, f[x][y]); for(int d = 0; d < 4; d ++){ int u = x + ha[d]; int v = y + co[d]; // cerr << u << " " << v << " t\n"; if(!kt(u, v) || f[u][v] <= f[x][y] + a[u][v]) continue; f[u][v] = f[x][y] + a[u][v]; q.push({f[u][v], u, v}); if(ph[u][v]){ ph[u][v]--; ph[u][v] = row(u, ph[u][v]); } if(pc[u][v]){ pc[u][v]--; pc[u][v] = col(pc[u][v], v); } } int l = max(1, x - k + 1), r = min(m, x + k - 1), a = max(1, y - k + 1), b = min(n, y + k - 1); if(xt >= l && xt <= r && yt >= a && yt <= b) ans = min(ans, f[x][y] + 1); // for(int d = 0; d < 4; d ++){ // int u = x + d * (k - 1); u = max(u, 1), u = min(u, m); // int v = y + d * (k - 1); v = max(v, 1), v = min(v, n); // if(f[u][v] > f[x][y] + 1){ // q.push({u, v}); // f[u][v] = f[x][y] + 1; // ph[u][v] = le[u][v]; // ph[u][v] = row(u, ph[u][v]); // pc[u][v] = up[u][v]; // pc[u][v] = col(pc[u][v], v); // } // } // cerr << " done\n"; if(l - 1 >= 1){ int lx = l - 1, pos = b; while(ph[lx][pos] >= a){ int g = ph[lx][pos]; if(f[lx][g] > f[x][y] + 1) f[lx][g] = f[x][y] + 1, q.push({f[lx][g], lx, g}); if(!ph[lx][pos]) break; ph[lx][pos]--; ph[lx][pos] = row(lx, ph[lx][pos]); } } if(r + 1 <= m){ int lx = r + 1, pos = b; while(ph[lx][pos] >= a){ int g = ph[lx][pos]; if(f[lx][g] > f[x][y] + 1) f[lx][g] = f[x][y] + 1, q.push({f[lx][g], lx, g}); if(!ph[lx][pos]) break; ph[lx][pos]--; ph[lx][pos] = row(lx, ph[lx][pos]); } } if(a - 1 >= 1){ int pos = r, ly = a - 1; while(pc[pos][ly] >= l){ int g = pc[pos][ly]; if(f[g][ly] > f[x][y] + 1) f[g][ly] = f[x][y] + 1, q.push({f[g][ly], g, ly}); if(!pc[g][ly]) break; pc[g][ly]--; pc[g][ly] = col(pc[g][ly], ly); } } if(b + 1 <= n){ int pos = r, ly = b + 1; while(pc[pos][ly] >= l){ int g = pc[pos][ly]; if(f[g][ly] > f[x][y] + 1) f[g][ly] = f[x][y] + 1, q.push({f[g][ly], g, ly}); if(!pc[g][ly]) break; pc[g][ly]--; pc[g][ly] = col(pc[g][ly], ly); } } } cout << min(ans, f[xt][yt]); }

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

Main.cpp: In function 'int main()':
Main.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(task ".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...