# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1012574 | 2024-07-02T11:01:10 Z | amirhoseinfar1385 | Wombats (IOI13_wombats) | C++17 | 0 ms | 0 KB |
#include "wombats.h" #include<bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") using namespace std; const unsigned int maxn=5000+10,maxm=200+10; unsigned int 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(unsigned int k=1;k<=m;k++){ for(unsigned int j=1;j<=m;j++){ ps[j]=ps[j-1]+allr[n][j-1]; } for(unsigned int j=m;j>=1;j--){ suf[j]=suf[j+1]+allr[n][j]; } for(unsigned 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(unsigned int j=1;j<=m;j++){ // cout<<dp[j][k]<<" "; // } // cout<<endl; psmx[0]=sufmx[m+1]=inf; for(unsigned int i=n-1;i>=1;i--){ for(unsigned int j=1;j<=m;j++){ ps[j]=ps[j-1]+allr[i][j-1]; } for(unsigned int j=m;j>=1;j--){ suf[j]=suf[j+1]+allr[i][j]; } for(unsigned int j=1;j<=m;j++){ psmx[j]=min(psmx[j-1],suf[j]+dp[j][k]+allc[i][j]); } for(unsigned int j=m;j>=1;j--){ sufmx[j]=min(sufmx[j+1],ps[j]+dp[j][k]+allc[i][j]); } for(unsigned int 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(unsigned int j=1;j<=m;j++){ // cout<<dp[j][k]<<" "; // } // cout<<endl; } } } void init(unsigned int R,unsigned int C,unsigned int H[5000][200],unsigned int V[5000][200]) { n=R; m=C; for(unsigned int i=1;i<=n;i++){ for(unsigned int j=1;j<=m-1;j++){ allr[i][j]=H[i-1][j-1]; } } for(unsigned int i=1;i<=n-1;i++){ for(unsigned int 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]; }