Submission #00001
ソースコード
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include<bits/stdc++.h> using namespace std; #define lol long long #define INF INT_MAX #define P pair<int,int> #define Pll pair<lol,lol> #define fi first #define se second #define mp(f,s) make_pair(f,s) const int mod = (1e9) + 7; // const int mod = 998244353; int dx[] = {0,1,0,-1}; int dy[] = {1,0,-1,0}; int main(){ int h,w; cin>>h>>w; vector<vector< int >> m(h,vector< int >(w,0)); vector<vector<lol>> dp(h,vector<lol>(w,0)); for ( int i=0;i<h;i++){ for ( int j=0;j<w;j++){ cin>>m[i][j]; } } queue<P> que; que.push(mp(0,0)); dp[0][0] += m[0][0]; while (!que.empty()){ P now = que.front(); que.pop(); for ( int i=0;i<2;i++){ P next = now; next.se += dx[i]; next.fi += dy[i]; if (next.fi >= h || next.se >= w ){ continue ; } lol value = dp[now.fi][now.se] + m[next.fi][next.se]; if (value > dp[next.fi][next.se] || dp[next.fi][next.se] == 0){ dp[next.fi][next.se] = value; que.push(next); } } } cout<<dp[h-1][w-1]<< "\n" ; return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 0001 - 百円以下の拾得物 |
ユーザー名 | ei2007 |
投稿日時 | 2022-05-20 14:34:09 |
言語 | C++17 |
状態 | Accepted |
得点 | 3 |
ソースコード長 | 1256 Byte |
最大実行時間 | 231 ms |
最大メモリ使用量 | 29560 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 3 / 3 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 55 ms | 604 KB |
1
|
in02.txt | AC | 20 ms | 700 KB |
1
|
in03.txt | AC | 23 ms | 664 KB |
1
|
in04.txt | AC | 20 ms | 632 KB |
1
|
in05.txt | AC | 35 ms | 600 KB |
1
|
in06.txt | AC | 208 ms | 16184 KB |
1
|
in07.txt | AC | 215 ms | 20092 KB |
1
|
in08.txt | AC | 231 ms | 24760 KB |
1
|
in09.txt | AC | 219 ms | 29560 KB |
1
|
in10.txt | AC | 37 ms | 17980 KB |
1
|
in11.txt | AC | 137 ms | 28408 KB |
1
|
sample_in_1.txt | AC | 20 ms | 20760 KB |
1
|
sample_in_2.txt | AC | 23 ms | 20732 KB |
1
|