結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
tkzw_21
|
| 提出日時 | 2015-01-12 01:05:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,237 bytes |
| コンパイル時間 | 1,958 ms |
| コンパイル使用メモリ | 168,100 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-22 04:25:02 |
| 合計ジャッジ時間 | 2,925 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 WA * 6 |
ソースコード
#include <bits/stdc++.h>
#define INF INT_MAX / 2
#define MOD 1000000007
using namespace std;
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PIPII;
typedef long long ll;
bool isKadomatsuSequence(int a2,int a1,int a0){
if(a2 == -1)return true;
if((a1 < a0 && a1 < a2 || a1 > a2 && a1 > a0) && a2 != a0)return true;
return false;
}
int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int m[101][101];
bool used[101][101];
int w,h;
int bfs(){
priority_queue<pair<int,pair<PI,int>>> pq;
pq.push(make_pair(0,make_pair(make_pair(0,0),-1)));
while(!pq.empty()){
pair<int,pair<PI,int>> p = pq.top();pq.pop();
int dist = p.first;
int y = p.second.first.first;
int x = p.second.first.second;
int prev = p.second.second;
if(y == h-1 && x == w-1)return dist;
used[y][x] = true;
for(int i=0;i<4;i++){
int ny = y + dy[i],nx = x + dx[i];
if(ny<0||ny>=h||nx<0||nx>=w|| !isKadomatsuSequence(prev,m[y][x],m[ny][nx]) )continue;
if(used[ny][nx])continue;
used[y][x] = true;
pq.push(make_pair(dist+1,make_pair(make_pair(ny,nx),m[y][x])));
}
}
return -1;
}
int main(void) {
cin >> w >> h;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin >> m[i][j];
}
}
int ans = bfs();
cout << ans << endl;
}
tkzw_21