結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-10 21:12:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 165 ms / 2,000 ms |
| コード長 | 897 bytes |
| コンパイル時間 | 2,272 ms |
| コンパイル使用メモリ | 199,832 KB |
| 最終ジャッジ日時 | 2025-01-09 15:50:49 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
void cmn(lint&x,lint y){if(x>y)x=y;}
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
lint h,w;std::cin>>h>>w;
std::vector<std::vector<lint>>g(h,std::vector<lint>(w));
for(lint i=0;i<h;i++){
for(lint j=0;j<w;j++){
char c;std::cin>>c;
g.at(i).at(j)=c=='k';
}}
lint inf=std::numeric_limits<lint>::max();
std::vector<std::vector<lint>>dp(h,std::vector<lint>(w,inf));
dp.at(0).at(0)=0;
for(lint i=0;i<h;i++){
for(lint j=0;j<w;j++){
if(g.at(i).at(j))dp.at(i).at(j)+=i+j;
if(i<h-1)cmn(dp.at(i+1).at(j),dp.at(i).at(j)+1);
if(j<w-1)cmn(dp.at(i).at(j+1),dp.at(i).at(j)+1);
}}
std::cout<<dp.at(h-1).at(w-1)<<'\n';
}
ngtkana