結果

問題 No.971 いたずらっ子
ユーザー yuji9511yuji9511
提出日時 2020-01-17 21:36:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,296 bytes
コンパイル時間 1,600 ms
コンパイル使用メモリ 164,260 KB
実行使用メモリ 39,040 KB
最終ジャッジ日時 2024-04-25 01:56:25
合計ジャッジ時間 2,923 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
38,912 KB
testcase_01 AC 52 ms
38,912 KB
testcase_02 AC 45 ms
37,760 KB
testcase_03 AC 43 ms
38,784 KB
testcase_04 AC 44 ms
37,120 KB
testcase_05 AC 42 ms
39,040 KB
testcase_06 AC 34 ms
34,304 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 14 ms
16,896 KB
testcase_09 AC 12 ms
16,256 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 6 ms
11,520 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dp[2010][2010] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W;
    cin >> H >> W;
    string a[2010];
    rep(i,0,H) cin >> a[i];
    rep(i,0,H+1){
        rep(j,0,W+1){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    rep(i,0,H){
        rep(j,0,W){
            if(i != 0){
                if(a[i][j] == '.'){
                    dp[i][j] = min(dp[i][j],dp[i-1][j] + 1);
                }else{
                    dp[i][j] = min(dp[i][j], dp[i-1][j] + 1 + i+j);
                }
            }
            if(j != 0){
                if(a[i][j] == '.'){
                    dp[i][j] = min(dp[i][j],dp[i][j-1] + 1);
                }else{
                    dp[i][j] = min(dp[i][j], dp[i][j-1] + 1 + i+j);
                }
            }
        }
    }
    print(dp[H-1][W-1]);

    

}
0