Submission #1265659

#TimeUsernameProblemLanguageResultExecution timeMemory
1265659kl0989eWombats (IOI13_wombats)C++20
55 / 100
20092 ms172792 KiB
#include "wombats.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define pb push_back #define vi vector<int> #define vl vector<ll> #define pi pair<int, int> #define pl pair<ll,ll> #define all(x) (x).begin(),(x).end() array<array<int,200>,5000> v,h; int n,m; array<array<array<int,200>,200>,2000> nodes; array<array<int,200>,200> opt; void buildnode(int vv, int i) { int l=i*10; int r=min(l+10,n-1); for (int j=0; j<m; j++) { nodes[vv][j][j]=0; for (int j2=j+1; j2<m; j2++) { nodes[vv][j][j2]=nodes[vv][j][j2-1]+h[l][j2-1]; nodes[vv][j2][j]=nodes[vv][j][j2]; } } for (int i=l; i<r; i++) { for (int j=0; j<m; j++) { for (int j2=0; j2<m; j2++) { nodes[vv][j][j2]+=v[i][j2]; } for (int j2=0; j2<m-1; j2++) { nodes[vv][j][j2+1]=min(nodes[vv][j][j2+1],nodes[vv][j][j2]+h[i+1][j2]); } for (int j2=m-2; j2>=0; j2--) { nodes[vv][j][j2]=min(nodes[vv][j][j2],nodes[vv][j][j2+1]+h[i+1][j2]); } } } } void unite(int vv) { for (int i=m-1; i>=0; i--) { for (int j=0; j<m; j++) { nodes[vv][i][j]=1e9; int l=(j==0?0:opt[i][j-1]); int r=(i==m-1?m-1:opt[i+1][j]); for (int k=l; k<=r; k++) { if (nodes[vv][i][j]>nodes[2*vv][i][k]+nodes[2*vv+1][k][j]) { opt[i][j]=k; nodes[vv][i][j]=nodes[2*vv][i][k]+nodes[2*vv+1][k][j]; } } } } } void build(int vv, int tl, int tr) { if (tl==tr) { buildnode(vv,tl); return; } int tm=tl+(tr-tl)/2; build(2*vv,tl,tm); build(2*vv+1,tm+1,tr); unite(vv); } void update(int ind, int vv, int tl, int tr) { if (tl==tr) { buildnode(vv,tl); return; } int tm=tl+(tr-tl)/2; if (ind<=tm) { build(2*vv,tl,tm); } else { build(2*vv+1,tm+1,tr); } unite(vv); } void update(int ind) { update(ind/10,1,0,(n-2)/10); } void init(int r, int c, int hh[5000][200], int vv[5000][200]) { n=r; m=c; for (int i=0; i<n; i++) { for (int j=0; j<m-1; j++) { h[i][j]=hh[i][j]; } } for (int i=0; i<n-1; i++) { for (int j=0; j<m; j++) { v[i][j]=vv[i][j]; } } build(1,0,(n-2)/10); } void changeH(int p, int q, int w) { h[p][q]=w; if (p!=0) { update(p-1); } if (p!=n-1) { update(p); } } void changeV(int p, int q, int w) { v[p][q]=w; update(p); } int escape(int v1, int v2) { return nodes[1][v1][v2]; }
#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...