Submission #1012496

#TimeUsernameProblemLanguageResultExecution timeMemory
1012496parsadox2Wombats (IOI13_wombats)C++17
0 / 100
7004 ms23128 KiB
#include <bits/stdc++.h> #include "wombats.h" #define F first #define S second using namespace std; const int N = 5e3 + 10 , M = 2e2 + 10 , Sq = 75 , inf = 1e9 + 10; int r , c , h[N][M] , v[N][M] , nex[Sq + 10][M][M] , adj[M][M] , ans[M][M] , dis[N][M] , dis2[Sq + 10][M] , las; bool is_update , marked[N][M]; void Dij(int Ps , int Qs) { int num = Ps / Sq , R = min(r - 1 , Ps + Sq); las = max(las , num); for(int i = Ps ; i <= R ; i++) for(int j = 0 ; j < c ; j++) { marked[i][j] = false; dis[i][j] = inf; } dis[Ps][Qs] = 0; priority_queue <pair<int , pair<int , int>> , vector <pair<int , pair<int , int>>> , greater<pair<int , pair<int , int>>>> pq; pq.push({Ps , {0 , Qs}}); while(!pq.empty()) { auto now = pq.top(); pq.pop(); int D = now.S.F , p = now.F , q = now.S.S; if(marked[p][q]) continue; marked[p][q] = true; if(p != Ps && p == R) continue; if(q + 1 < c && D + h[p][q] < dis[p][q + 1]) { dis[p][q + 1] = D + h[p][q]; pq.push({p , {dis[p][q + 1] , q + 1}}); } if(q - 1 >= 0 && D + h[p][q - 1] < dis[p][q - 1]) { dis[p][q - 1] = D + h[p][q - 1]; pq.push({p , {dis[p][q - 1] , q - 1}}); } if(p + 1 <= R && D + v[p][q] < dis[p + 1][q]) { dis[p + 1][q] = D + v[p][q]; pq.push({p + 1 , {dis[p + 1][q] , q}}); } } for(int i = 0 ; i < c ; i++) { //cout << Ps << " " << Qs << " " << R << " " << i << " : " << dis[R][i] << endl; nex[num][Qs][i] = dis[R][i]; } if(num == 0) { for(int i = 0 ; i < c ; i++) adj[Qs][i] = dis[Ps][i]; } } void Solve(int Qs) { for(int i = 0 ; i < las + 2 ; i++) for(int j = 0 ; j < c ; j++) { dis2[i][j] = inf; } for(int i = 0 ; i < c ; i++) dis2[0][i] = adj[Qs][i]; for(int i = 0 ; i <= las ; i++) { for(int j = 0 ; j < c ; j++) for(int k = 0 ; k < c ; k++) { dis2[i + 1][k] = min(dis2[i + 1][k] , dis2[i][j] + nex[i][j][k]); //cout << i << " " << j << " " << k << " " << dis2[i][j] << " " << nex[i][j][k] << endl; } } for(int i = 0 ; i < c ; i++) { //cout << Qs << " " << i << " : " << dis2[las + 1][i] << endl; ans[Qs][i] = dis2[las + 1][i]; } } void init(int R , int C , int H[5000][200] , int V[5000][200]) { r = R; c = C; for(int i = 0 ; i < R ; i++) for(int j = 0 ; j + 1 < C ; j++) h[i][j] = H[i][j]; for(int i = 0 ; i + 1 < R ; i++) for(int j = 0 ; j < C ; j++) v[i][j] = V[i][j]; for(int i = 0 ; i < R ; i += Sq) for(int j = 0 ; j < C ; j++) Dij(i , j); } void changeH(int P , int Q , int W) { is_update = false; h[P][Q] = W; for(int j = 0 ; j < c ; j++) { Dij(P / Sq , j); } } void changeV(int P , int Q , int W) { is_update = false; v[P][Q] = W; for(int j = 0 ; j < c ; j++) Dij(P / Sq , j); } int escape(int v1 , int v2) { if(!is_update) { for(int i = 0 ; i < c ; i++) Solve(i); is_update = true; } return ans[v1][v2]; }

Compilation message (stderr)

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
#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...