結果
問題 |
No.124 門松列(3)
|
ユーザー |
![]() |
提出日時 | 2016-06-04 16:09:52 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,454 bytes |
コンパイル時間 | 602 ms |
コンパイル使用メモリ | 70,460 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-08 07:56:16 |
合計ジャッジ時間 | 1,647 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 4 |
other | WA * 26 |
ソースコード
#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; } } } k++; } for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { cout << d[i][j] << ' '; } cout << '\n'; } cout << d[W - 1][H - 1]; return 0; }