Submission #1012545

#TimeUsernameProblemLanguageResultExecution timeMemory
1012545amirhoseinfar1385Wombats (IOI13_wombats)C++17
55 / 100
20059 ms35240 KiB
#include "wombats.h" #include<bits/stdc++.h> using namespace std; const long long maxn=5000+10,maxm=200+10; long long allr[maxn][maxm],allc[maxn][maxm],dp[maxn][maxm],n,m,ps[maxm],suf[maxm],inf=1e11+5,psmx[maxn],sufmx[maxn]; void calc(){ for(long long k=1;k<=m;k++){ for(long long j=1;j<=m;j++){ ps[j]=ps[j-1]+allr[n][j-1]; } for(long long j=m;j>=1;j--){ suf[j]=suf[j+1]+allr[n][j]; } for(int j=1;j<=m;j++){ if(j<=k){ dp[j][k]=ps[k]-ps[j]; }else{ dp[j][k]=suf[k]-suf[j]; } } // for(long long j=1;j<=m;j++){ // cout<<dp[j][k]<<" "; // } // cout<<endl; psmx[0]=sufmx[m+1]=inf; for(long long i=n-1;i>=1;i--){ for(long long j=1;j<=m;j++){ ps[j]=ps[j-1]+allr[i][j-1]; } for(long long j=m;j>=1;j--){ suf[j]=suf[j+1]+allr[i][j]; } for(long long j=1;j<=m;j++){ psmx[j]=min(psmx[j-1],suf[j]+dp[j][k]+allc[i][j]); } for(long long j=m;j>=1;j--){ sufmx[j]=min(sufmx[j+1],ps[j]+dp[j][k]+allc[i][j]); } for(long long j=1;j<=m;j++){ // cout<<psmx[j-1]<<" "<<suf[j]<<" "<<sufmx[j+1]<<" "<<ps[j]<<endl; dp[j][k]=min(dp[j][k]+allc[i][j],min(psmx[j-1]-suf[j],sufmx[j+1]-ps[j])); } // cout<<"salam"<<endl; // for(long long j=1;j<=m;j++){ // cout<<dp[j][k]<<" "; // } // cout<<endl; } } } void init(int R,int C,int H[5000][200],int V[5000][200]) { n=R; m=C; for(long long i=1;i<=n;i++){ for(long long j=1;j<=m-1;j++){ allr[i][j]=H[i-1][j-1]; } } for(long long i=1;i<=n-1;i++){ for(long long j=1;j<=m;j++){ allc[i][j]=V[i-1][j-1]; } } calc(); } void changeH(int P,int Q,int W) { P++; Q++; allr[P][Q]=W; calc(); } void changeV(int P,int Q,int W) { P++; Q++; allc[P][Q]=W; calc(); } int escape(int V1,int V2) { V1++; V2++; return dp[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...