結果
問題 | No.971 いたずらっ子 |
ユーザー |
|
提出日時 | 2020-01-17 21:36:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 1,296 bytes |
コンパイル時間 | 1,849 ms |
コンパイル使用メモリ | 167,856 KB |
実行使用メモリ | 39,040 KB |
最終ジャッジ日時 | 2024-11-07 11:24:48 |
合計ジャッジ時間 | 3,467 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
/*** 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]); }