結果
問題 |
No.124 門松列(3)
|
ユーザー |
![]() |
提出日時 | 2015-01-12 00:37:56 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,706 bytes |
コンパイル時間 | 610 ms |
コンパイル使用メモリ | 89,092 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-22 04:16:29 |
合計ジャッジ時間 | 1,403 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 22 WA * 4 |
ソースコード
#include <iostream> #include <cstdio> #include <string> #include <sstream> #include <algorithm> #include <math.h> #include <map> #include <iomanip> #include <vector> #include <queue> #include <set> #define PI 3.14159265359 #define INF 99999999; #define rep(i, n) for(int i=0; i<n; i++) #define REP(n) rep(i, n) #define EPS 1e-10 typedef long long ll; using namespace std; /* class Target { public: vector <string> draw(int n) { } }; */ class Pos { public: //書かれている数字 int num; int x, y, cnt; int pre; Pos(int pnum, int px, int py, int pcnt, int ppre) { num = pnum; x = px; y = py; cnt = pcnt; pre = ppre; } }; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int main() { int W, H, M[100][100]; bool bM[100][100] = {false}; cin >> W >> H; rep(i, H) rep(j, W) cin >> M[i][j]; bool flag = false; queue<Pos> q; q.push(Pos(M[0][0], 0, 0, 0, 0)); q.push(Pos(M[0][0], 0, 0, 0, 10)); bM[0][0] = true; while (!q.empty()) { Pos now = q.front(); q.pop(); if (now.x == W - 1 && now.y == H - 1) { cout << now.cnt << endl; flag = true; break; } for (int i=0; i<4; i++) { int nx = now.x + dx[i]; int ny = now.y + dy[i]; if (0<=nx && nx<W && 0<=ny && ny<H && M[ny][nx] != now.pre && !bM[ny][nx]) { if (now.pre < now.num) { if (M[ny][nx] < now.num) { Pos next = Pos(M[ny][nx], nx, ny, now.cnt + 1, now.num); bM[ny][nx] = true; q.push(next); } } else { if (M[ny][nx] > now.num) { Pos next = Pos(M[ny][nx], nx, ny, now.cnt + 1, now.num); bM[ny][nx] = true; q.push(next); } } } } } if (!flag) { cout << -1 << endl; } return 0; }