제출 #897436

#제출 시각아이디문제언어결과실행 시간메모리
897436Faisal_Saqib웜뱃 (IOI13_wombats)C++17
55 / 100
20092 ms20068 KiB
#include "wombats.h" #include <iostream> #include <set> using namespace std; int h[5000][200]; int v[5000][200]; int dist[5000][200]; int dist_level[2][5000][2]; int n,m; int ans=0; bool Valid(int i,int j){ return (0<=i and i<n and 0<=j and j<m); } void khatam(int st) { set<pair<int,pair<int,int>>> sp; dist_level[st][0][st]=0; sp.insert({0,{0,st}}); while(sp.size()) { auto f=*begin(sp); sp.erase(begin(sp)); if(Valid(f.second.first+1,f.second.second) and dist_level[st][f.second.first+1][f.second.second]>(f.first+v[f.second.first][f.second.second])) { sp.erase({dist_level[st][f.second.first+1][f.second.second],{f.second.first+1,f.second.second}}); dist_level[st][f.second.first+1][f.second.second]=(f.first+v[f.second.first][f.second.second]); sp.insert({dist_level[st][f.second.first+1][f.second.second],{f.second.first+1,f.second.second}}); } if(Valid(f.second.first,f.second.second+1) and dist_level[st][f.second.first][f.second.second+1]>(f.first+h[f.second.first][f.second.second])) { sp.erase({dist_level[st][f.second.first][f.second.second+1],{f.second.first,f.second.second+1}}); dist_level[st][f.second.first][f.second.second+1]=(f.first+h[f.second.first][f.second.second]); sp.insert({dist_level[st][f.second.first][f.second.second+1],{f.second.first,f.second.second+1}}); } if(Valid(f.second.first,f.second.second-1) and dist_level[st][f.second.first][f.second.second-1]>(f.first+h[f.second.first][f.second.second-1])) { sp.erase({dist_level[st][f.second.first][f.second.second-1],{f.second.first,f.second.second-1}}); dist_level[st][f.second.first][f.second.second-1]=(f.first+h[f.second.first][f.second.second-1]); sp.insert({dist_level[st][f.second.first][f.second.second-1],{f.second.first,f.second.second-1}}); } } } void init(int r, int c, int H[5000][200], int V[5000][200]) { n=r; m=c; for(int i=0;i<r;i++) { for(int j=0;j<(c-1);j++) { ans+=H[i][j]; h[i][j]=H[i][j]; } } for(int i=0;i<(r-1);i++) { for(int j=0;j<c;j++) { ans+=V[i][j]; v[i][j]=V[i][j]; } } } void changeH(int p, int q, int w) { ans-=h[p][q]; ans+=w; h[p][q]=w; if(m==2) { for(int st=0;st<m;st++) { for(int i=0;i<n;i++) for(int j=0;j<m;j++) dist_level[st][i][j]=1e18; khatam(st); } } } void changeV(int p, int q, int w) { ans-=v[p][q]; ans+=w; v[p][q]=w; if(m==2) { for(int st=0;st<m;st++) { for(int i=0;i<n;i++) for(int j=0;j<m;j++) dist_level[st][i][j]=1e18; khatam(st); } } } int escape(int V1, int V2) { if(m==1) return ans; else if(m==2) return dist_level[V1][n-1][V2]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) dist[i][j]=1e18; set<pair<int,pair<int,int>>> sp; dist[0][V1]=0; sp.insert({0,{0,V1}}); while(sp.size()) { auto f=*begin(sp); if(f.second.first==(n-1) and f.second.second==V2) return f.first; sp.erase(begin(sp)); if(Valid(f.second.first+1,f.second.second) and dist[f.second.first+1][f.second.second]>(f.first+v[f.second.first][f.second.second])) { sp.erase({dist[f.second.first+1][f.second.second],{f.second.first+1,f.second.second}}); dist[f.second.first+1][f.second.second]=(f.first+v[f.second.first][f.second.second]); sp.insert({dist[f.second.first+1][f.second.second],{f.second.first+1,f.second.second}}); } if(Valid(f.second.first,f.second.second+1) and dist[f.second.first][f.second.second+1]>(f.first+h[f.second.first][f.second.second])) { sp.erase({dist[f.second.first][f.second.second+1],{f.second.first,f.second.second+1}}); dist[f.second.first][f.second.second+1]=(f.first+h[f.second.first][f.second.second]); sp.insert({dist[f.second.first][f.second.second+1],{f.second.first,f.second.second+1}}); } if(Valid(f.second.first,f.second.second-1) and dist[f.second.first][f.second.second-1]>(f.first+h[f.second.first][f.second.second-1])) { sp.erase({dist[f.second.first][f.second.second-1],{f.second.first,f.second.second-1}}); dist[f.second.first][f.second.second-1]=(f.first+h[f.second.first][f.second.second-1]); sp.insert({dist[f.second.first][f.second.second-1],{f.second.first,f.second.second-1}}); } } return 0; }

컴파일 시 표준 에러 (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;
      |      ^~~
wombats.cpp: In function 'void changeH(int, int, int)':
wombats.cpp:75:27: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   75 |      dist_level[st][i][j]=1e18;
      |                           ^~~~
wombats.cpp: In function 'void changeV(int, int, int)':
wombats.cpp:91:27: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   91 |      dist_level[st][i][j]=1e18;
      |                           ^~~~
wombats.cpp: In function 'int escape(int, int)':
wombats.cpp:104:15: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
  104 |    dist[i][j]=1e18;
      |               ^~~~
#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...