結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
nona_cat_puyo
|
| 提出日時 | 2016-06-04 16:31:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,379 bytes |
| コンパイル時間 | 677 ms |
| コンパイル使用メモリ | 70,336 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-08 07:57:07 |
| 合計ジャッジ時間 | 1,690 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 WA * 9 |
ソースコード
#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 < W; i++) {
for (int j = 0; j < H; j++) {
cin >> M[i][j];
}
}
for (int i = 0; i < W; i++) {
for (int j = 0; j < H; 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 <= 10000) {
PP p = que.front(); que.pop();
for (int i = 0; i < 4; i++) {
int nx = p.first.first + dx[i];
int ny = p.first.second + dy[i];
int b = M[p.first.first][p.first.second];
int bb = p.second.second;
if (0 <= nx && nx < W && 0 <= ny && ny < H) {
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[W - 1][H - 1] != -1) break;
k++;
}
cout << d[W - 1][H - 1];
return 0;
}
nona_cat_puyo