# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
18089 | comet | L 모양의 종이 자르기 (KOI15_cut) | C++98 | 244 ms | 27508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int dp[51][51][51][51];
int f(int N,int M,int x,int y){
if(x==0||y==0)x=y=0;
if(x==0&&y==0){
if(N==1)return M;
if(M==1)return N;
if(N==M)return 1;
}
// if(x==N&&y==M)return 0;
int& ret=dp[N][M][x][y];
if(~ret)return ret;
ret=1e9;
// y-axis
for(int i=1;i<=x;i++){
ret=min(ret,f(i,M-y,0,0)+f(N-i,M,x-i,y));
}
for(int i=x+1;i<N;i++){
ret=min(ret,f(i,M,x,y)+f(N-i,M,0,0));
}
// x-axis
for(int i=1;i<M-y;i++){
ret=min(ret,f(N,i,0,0)+f(N,M-i,x,y));
}
for(int i=M-y;i<M;i++){
ret=min(ret,f(N,i,x,i-(M-y))+f(N-x,M-i,0,0));
}
return ret;
}
int main(){
memset(dp,-1,sizeof(dp));
int N,M,x,y;
scanf("%d%d%d%d",&N,&M,&x,&y);
printf("%d\n",f(N,M,x,y));
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |