Submission #936591

#TimeUsernameProblemLanguageResultExecution timeMemory
936591penguin133Maze (JOI23_ho_t3)C++17
19 / 100
2136 ms1730536 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); vector <pi> adj[10000005]; int cnt, n, q; struct node{ int s, e, m; int nd, nd2; node *l, *r; node(int _s, int _e){ s = _s, e = _e, m = (s + e) >> 1; nd = cnt++; nd2 = cnt++; if(s == e){ adj[s].push_back({nd2, 0}); adj[nd].push_back({s, 0}); } else{ l = new node(s, m); r = new node(m+1, e); adj[nd].push_back({l->nd, 0}); adj[nd].push_back({r->nd, 0}); adj[r->nd2].push_back({nd2, 0}); adj[l->nd2].push_back({nd2, 0}); } } void upd(int a, int b, int u, int v){ if(s == a && b == e){ adj[u].push_back({nd, v}); return; } if(b <= m)l->upd(a, b, u, v); else if(a > m)r->upd(a, b, u, v); else l->upd(a, m, u, v), r->upd(m+1, b, u, v); } void upd2(int a, int b, int u, int v){ if(s == a && b == e){ adj[nd2].push_back({u, v}); return; } if(b <= m)l->upd2(a, b, u, v); else if(a > m)r->upd2(a, b, u, v); else l->upd2(a, m, u, v), r->upd2(m+1, b, u, v); } }*root; char A[6000005]; int r, c; inline int conv(int x, int y){ return (x - 1) * c + y; } int dist[10000005]; void solve(){ cin >> r >> c >> n; int a, b, cc, d; cin >> a >> b >> cc >> d; cnt = r * c + 1; root = new node(1, r * c); if(r > c){ for(int i = 1; i <= r; i++){ for(int j = 1; j <= c; j++)cin >> A[conv(j, i)]; } swap(r, c); } else for(int i = 1; i <= r; i++)for(int j = 1; j <= c; j++)cin >> A[conv(i, j)]; for(int i = 1; i <= r * c; i++){ if(i > c && A[i - c] == '.')adj[i].push_back({i - c, 0}); if(i <= c * (r - 1) && A[i + c] == '.')adj[i].push_back({i + c, 0}); if(i % c != 1 && A[i - 1] == '.')adj[i].push_back({i - 1, 0}); if(i % c && A[i + 1] == '.')adj[i].push_back({i + 1, 0}); int aaa = (i - 1) / c + 1; for(int j = max(-n, -aaa + 1); j <= min(n, r - aaa); j++){ if((i - 1) / c + 1 + j <= 0 || (i - 1) / c + 1 + j > r)continue; if(j == -n || j == n){ int lft = max(1ll, (i - 1) % c + 1 - n + 1); int rgt = min(c, (i - 1) % c + 1 + n - 1); root->upd(conv((i - 1) / c + 1 + j, lft), conv((i - 1) / c + j + 1, rgt), i, 1); } else{ int lft = max(1ll, (i - 1) % c + 1 - n); int rgt = min(c, (i - 1) % c + 1 + n); root->upd(conv((i - 1) / c + 1 + j, lft), conv((i - 1) / c + j + 1, rgt), i, 1); } } } for(int i = 1; i <= cnt; i++)dist[i] = 1e18; dist[conv(a, b)] = 0; //for(auto [i, j] : adj[conv(a, b)])cout << i << ' ' << j << '\n'; deque <int> dq; dq.push_back(conv(a, b)); while(!dq.empty()){ int x = dq.front(); dq.pop_front(); for(auto [i, j] : adj[x]){ if(dist[i] > dist[x] + j){ dist[i] = dist[x] + j; if(j)dq.push_back(i); else dq.push_front(i); } } } //for(int i = 1; i <= cnt; i++)cout << dist[i] << ' '; cout << dist[conv(cc, d)]; } main(){ ios::sync_with_stdio(0);cin.tie(0); int tc = 1; //cin >> tc; for(int tc1=1;tc1<=tc;tc1++){ // cout << "Case #" << tc1 << ": "; solve(); } }

Compilation message (stderr)

Main.cpp:120:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  120 | main(){
      | ^~~~
#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...