結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
nona_cat_puyo
|
| 提出日時 | 2016-06-05 13:32:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,386 bytes |
| コンパイル時間 | 2,038 ms |
| コンパイル使用メモリ | 70,868 KB |
| 実行使用メモリ | 33,680 KB |
| 最終ジャッジ日時 | 2024-10-08 15:35:52 |
| 合計ジャッジ時間 | 3,048 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 WA * 3 |
ソースコード
#include <iostream>
#include <math.h>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, P> PP;
int W, H;
int M[100][100];
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int d[100][100] = { 0 };
bool isKadomatsu(int a, int b, int c) {
if (a == 0 || b == 0) return true;
if ((a == b) || (b == c) || (a == c)) {
return false;
}
else {
return !(((a < b) && (b < c)) || ((a > b) && (b > c)));
}
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cin >> W >> H;
int k = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> M[i][j];
}
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
d[i][j] = -1;
}
}
d[0][0] = 0;
queue<PP> que;
que.push(PP(P(0, 0), P(0, 0)));
while (que.size() && k <= 1000000) {
PP p = que.front(); que.pop();
int b = M[p.first.first][p.first.second];
int bb = p.second.second;
for (int i = 0; i < 4; i++) {
int nx = p.first.first + dx[i];
int ny = p.first.second + dy[i];
if (0 <= nx && nx < H && 0 <= ny && ny < W) {
if (isKadomatsu(bb, b, M[nx][ny])) {
que.push(PP(P(nx, ny), P(bb, b)));
d[nx][ny] = d[p.first.first][p.first.second] + 1;
}
}
}
if (d[H - 1][W - 1] != -1) break;
k++;
}
cout << d[H - 1][W - 1];
return 0;
}
nona_cat_puyo