結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-17 21:44:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,315 bytes |
| コンパイル時間 | 2,060 ms |
| コンパイル使用メモリ | 175,940 KB |
| 実行使用メモリ | 75,136 KB |
| 最終ジャッジ日時 | 2024-06-25 19:18:05 |
| 合計ジャッジ時間 | 10,848 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 WA * 5 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PL;
typedef pair<int, int> P;
typedef pair<PL, P> E;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);
#define l_ength size
void mul_mod(ll& a, ll b){
a *= b;
a %= MOD;
}
void add_mod(ll& a, ll b){
a = (a<MOD)?a:(a-MOD);
b = (b<MOD)?b:(b-MOD);
a += b;
a = (a<MOD)?a:(a-MOD);
}
int h,w;
PL dist[2020][2020];
string a[2020];
bool check(int i, int j){
return (0<=i&&i<h&&0<=j&&j<w);
}
priority_queue<E, vector<E>, greater<E> > pq;
int main(void){
int dx[4]={-1,0,0,1},dy[4]={0,-1,1,0},i,j,k,x,y;
ll c,e; PL tmp;
fill(dist[0],dist[2020],PL(INFLL,INFLL));
dist[0][0] = PL(0ll,0ll); pq.push(E(dist[0][0],P(0,0)));
cin >> h >> w;
for(i=0; i<h; ++i){
cin >> a[i];
}
while(!pq.empty()){
i = pq.top().second.first;
j = pq.top().second.second;
c = pq.top().first.first;
e = pq.top().first.second;
pq.pop();
if(dist[i][j] < PL(c,e)){
continue;
}
for(k=0; k<4; ++k){
x = i + dx[k];
y = j + dy[k];
if(!check(x,y)){
continue;
}
tmp = PL(c+1,e+1);
if(a[x][y]=='k'){
tmp.first += tmp.second;
}
if(dist[x][y] > tmp){
dist[x][y] = tmp;
pq.push(E(dist[x][y],P(x,y)));
}
}
}
cout << dist[h-1][w-1].first << endl;
return 0;
}