Submission #3329998
Source Code Expand
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; void fmin(int&a,int b){ if(b<a)a=b; } int s[41][41],f[41][41][41][41]; char str[41]; int get(int i,int j,int k,int l){ if(i>k||j>l)return 0; return s[k][l]-s[i-1][l]-s[k][j-1]+s[i-1][j-1]; } int main(){ int n,m,i,j,k,l,x,y,sx,sy,ans; scanf("%d%d",&n,&m); for(i=1;i<=n;i++){ scanf("%s",str+1); for(j=1;j<=m;j++){ if(str[j]=='P'){ sx=i; sy=j; } s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+(str[j]=='#'); } } memset(f,63,sizeof(f)); ans=f[0][0][0][0]; f[1][1][n][m]=0; for(i=1;i<=sx;i++){ for(j=1;j<=sy;j++){ for(k=n;k>=sx;k--){ for(l=m;l>=sy;l--){ fmin(ans,f[i][j][k][l]+min(min(get(i,j,sx,sy),get(i,sy,sx,l)),min(get(sx,j,k,sy),get(sx,sy,k,l)))); for(x=i;x<=k;x++){ for(y=j;y<=l;y++){ if(sx<=x&&sy<=y)fmin(f[i][j][x][y],f[i][j][k][l]+get(i,y+1,x,l)+get(x+1,j,k,y)); if(x<=sx&&sy<=y)fmin(f[i][y][x][l],f[i][j][k][l]+get(i,j,x,y-1)+get(x+1,y,k,l)); if(x<=sx&&y<=sy)fmin(f[x][y][k][l],f[i][j][k][l]+get(i,y,x-1,l)+get(x,j,k,y-1)); if(sx<=x&&y<=sy)fmin(f[x][j][k][y],f[i][j][k][l]+get(i,j,x-1,y)+get(x,y+1,k,l)); } } } } } } printf("%d",ans); }
Submission Info
Submission Time | |
---|---|
Task | H - Poor Penguin |
User | jefflyy |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1269 Byte |
Status | WA |
Exec Time | 852 ms |
Memory | 11264 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:16:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d",&n,&m); ^ ./Main.cpp:18:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",str+1); ^
Judge Result
Set Name | sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1600 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
All | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, 01-49.txt, 01-50.txt, 01-51.txt, 01-52.txt, 01-53.txt, 01-54.txt, 01-55.txt, 01-56.txt, 01-57.txt, 01-58.txt, 01-59.txt, 01-60.txt, 01-61.txt, 01-62.txt, 01-63.txt, 01-64.txt, 01-65.txt, 01-66.txt, 01-67.txt, 01-68.txt, 01-69.txt, 01-70.txt, 01-71.txt, 01-72.txt, 01-73.txt, 01-74.txt, 01-75.txt, 01-76.txt, 01-77.txt, 01-78.txt, 01-79.txt, 01-80.txt, 01-81.txt, 01-82.txt, 01-83.txt, 01-84.txt, 01-85.txt, 01-86.txt, 01-87.txt, 01-88.txt, 01-89.txt, 01-90.txt, 01-91.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 4 ms | 11136 KB |
01-02.txt | AC | 4 ms | 11136 KB |
01-03.txt | AC | 15 ms | 11264 KB |
01-04.txt | AC | 494 ms | 11264 KB |
01-05.txt | AC | 174 ms | 11264 KB |
01-06.txt | AC | 203 ms | 11264 KB |
01-07.txt | AC | 850 ms | 11264 KB |
01-08.txt | AC | 851 ms | 11264 KB |
01-09.txt | AC | 849 ms | 11264 KB |
01-10.txt | AC | 850 ms | 11264 KB |
01-11.txt | AC | 852 ms | 11264 KB |
01-12.txt | AC | 850 ms | 11264 KB |
01-13.txt | AC | 850 ms | 11264 KB |
01-14.txt | AC | 850 ms | 11264 KB |
01-15.txt | AC | 851 ms | 11264 KB |
01-16.txt | AC | 4 ms | 11136 KB |
01-17.txt | AC | 4 ms | 11264 KB |
01-18.txt | WA | 722 ms | 11264 KB |
01-19.txt | WA | 775 ms | 11264 KB |
01-20.txt | WA | 830 ms | 11264 KB |
01-21.txt | WA | 843 ms | 11264 KB |
01-22.txt | WA | 671 ms | 11264 KB |
01-23.txt | WA | 818 ms | 11136 KB |
01-24.txt | WA | 785 ms | 11264 KB |
01-25.txt | WA | 831 ms | 11264 KB |
01-26.txt | WA | 820 ms | 11264 KB |
01-27.txt | WA | 827 ms | 11264 KB |
01-28.txt | WA | 522 ms | 11264 KB |
01-29.txt | WA | 744 ms | 11264 KB |
01-30.txt | AC | 580 ms | 11264 KB |
01-31.txt | WA | 494 ms | 11264 KB |
01-32.txt | AC | 583 ms | 11264 KB |
01-33.txt | WA | 804 ms | 11264 KB |
01-34.txt | AC | 742 ms | 11264 KB |
01-35.txt | AC | 778 ms | 11264 KB |
01-36.txt | WA | 848 ms | 11264 KB |
01-37.txt | AC | 737 ms | 11264 KB |
01-38.txt | WA | 793 ms | 11264 KB |
01-39.txt | WA | 831 ms | 11264 KB |
01-40.txt | WA | 771 ms | 11264 KB |
01-41.txt | WA | 713 ms | 11264 KB |
01-42.txt | WA | 729 ms | 11264 KB |
01-43.txt | WA | 785 ms | 11264 KB |
01-44.txt | WA | 810 ms | 11264 KB |
01-45.txt | WA | 641 ms | 11264 KB |
01-46.txt | WA | 668 ms | 11264 KB |
01-47.txt | WA | 795 ms | 11264 KB |
01-48.txt | WA | 849 ms | 11264 KB |
01-49.txt | WA | 829 ms | 11264 KB |
01-50.txt | WA | 840 ms | 11264 KB |
01-51.txt | WA | 777 ms | 11264 KB |
01-52.txt | WA | 800 ms | 11264 KB |
01-53.txt | WA | 667 ms | 11264 KB |
01-54.txt | WA | 839 ms | 11264 KB |
01-55.txt | WA | 737 ms | 11264 KB |
01-56.txt | WA | 831 ms | 11264 KB |
01-57.txt | WA | 804 ms | 11264 KB |
01-58.txt | WA | 762 ms | 11264 KB |
01-59.txt | WA | 839 ms | 11264 KB |
01-60.txt | WA | 791 ms | 11264 KB |
01-61.txt | WA | 821 ms | 11264 KB |
01-62.txt | WA | 639 ms | 11264 KB |
01-63.txt | WA | 799 ms | 11264 KB |
01-64.txt | WA | 785 ms | 11264 KB |
01-65.txt | WA | 844 ms | 11264 KB |
01-66.txt | WA | 792 ms | 11264 KB |
01-67.txt | WA | 794 ms | 11264 KB |
01-68.txt | WA | 849 ms | 11264 KB |
01-69.txt | WA | 748 ms | 11264 KB |
01-70.txt | WA | 735 ms | 11264 KB |
01-71.txt | WA | 840 ms | 11264 KB |
01-72.txt | WA | 693 ms | 11264 KB |
01-73.txt | WA | 828 ms | 11264 KB |
01-74.txt | WA | 838 ms | 11136 KB |
01-75.txt | WA | 776 ms | 11264 KB |
01-76.txt | WA | 848 ms | 11264 KB |
01-77.txt | WA | 679 ms | 11264 KB |
01-78.txt | WA | 660 ms | 11264 KB |
01-79.txt | WA | 844 ms | 11264 KB |
01-80.txt | WA | 769 ms | 11264 KB |
01-81.txt | WA | 820 ms | 11264 KB |
01-82.txt | WA | 699 ms | 11264 KB |
01-83.txt | WA | 839 ms | 11264 KB |
01-84.txt | WA | 777 ms | 11264 KB |
01-85.txt | WA | 802 ms | 11264 KB |
01-86.txt | WA | 703 ms | 11264 KB |
01-87.txt | WA | 788 ms | 11264 KB |
01-88.txt | WA | 808 ms | 11264 KB |
01-89.txt | WA | 799 ms | 11264 KB |
01-90.txt | WA | 800 ms | 11264 KB |
01-91.txt | WA | 611 ms | 11264 KB |
sample-01.txt | AC | 4 ms | 11136 KB |
sample-02.txt | AC | 4 ms | 11136 KB |
sample-03.txt | AC | 846 ms | 11264 KB |
sample-04.txt | AC | 4 ms | 11136 KB |