# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1012575 | amirhoseinfar1385 | 웜뱃 (IOI13_wombats) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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=100+10;
unsigned int allr[maxn][maxm],allc[maxn][maxm],dp[maxn][maxm],n,m,ps[maxm],suf[maxm],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( int R, int C, int H[5000][200], 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];
}