Submission #61823


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int a[1005][1005];
vector<vector<int>> m(1005,vector<int>(1005,-1));
int dp(int h,int w);
signed main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int h,w;
cin>>h>>w;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin>>a[i][j];
}
}
cout<<dp(h-1,w-1)<<"\n";
return 0;
}
int dp(int h,int w){
if(h==0&&w==0){
m[h][w]=a[h][w];
return m[h][w];
}
if(h==0){
if(m[h][w]<0){
m[h][w]=a[h][w]+dp(h,w-1);
}
return m[h][w];
}
if(w==0){
if(m[h][w]<0){
m[h][w]=a[h][w]+dp(h-1,w);
}
return m[h][w];
}
if(m[h][w]<0){
m[h][w]=max(a[h][w]+dp(h-1,w),a[h][w]+dp(h,w-1));
}
return m[h][w];
}

ステータス

項目 データ
問題 0910 - 百円以下の拾得物
ユーザー名 ei2009
投稿日時 2020-08-07 12:03:49
言語 C++17
状態 Accepted
得点 3
ソースコード長 889 Byte
最大実行時間 81 ms
最大メモリ使用量 8660 KB

セット

セット 得点 Cases
1 ALL 3 / 3 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.txt AC 30 ms 4572 KB
1
in02.txt AC 20 ms 4372 KB
1
in03.txt AC 27 ms 4408 KB
1
in04.txt AC 19 ms 4444 KB
1
in05.txt AC 27 ms 4496 KB
1
in06.txt AC 77 ms 8660 KB
1
in07.txt AC 79 ms 8644 KB
1
in08.txt AC 81 ms 8636 KB
1
in09.txt AC 81 ms 8628 KB
1
in10.txt AC 30 ms 4908 KB
1
in11.txt AC 61 ms 7548 KB
1
sample_in_1.txt AC 20 ms 4520 KB
1
sample_in_2.txt AC 26 ms 4572 KB
1