結果
問題 |
No.124 門松列(3)
|
ユーザー |
|
提出日時 | 2021-02-23 21:36:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,850 bytes |
コンパイル時間 | 904 ms |
コンパイル使用メモリ | 101,988 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 15:50:37 |
合計ジャッジ時間 | 1,877 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 WA * 1 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; bool bo[4][110][110] = { false }; int b1[4] = { 0,0,1,-1 }; int b2[4] = { 1,-1,0,0 }; int m[110][110]; int main() { int w, h; cin >> w >> h; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> m[i][j]; } } queue<tuple<int, int, int, int, int>> que; if (m[0][0] < m[0][1]) { que.push(make_tuple(1, 0, 1, 0, m[0][0])); bo[0][0][1] = true; } if (m[0][0] > m[0][1]) { que.push(make_tuple(1, 0, 1, 1, m[0][0])); bo[0][0][1] = true; } if (m[0][0] < m[1][0]) { que.push(make_tuple(1, 1, 0, 0, m[0][0])); bo[2][1][0] = true; } if (m[0][0] < m[1][0]) { que.push(make_tuple(1, 1, 0, 1, m[0][0])); bo[2][1][0] = true; } while (!que.empty()) { tuple<int, int, int, int, int> t = que.front(); int a = get<0>(t); int x = get<1>(t); int y = get<2>(t); int z = get<3>(t); int mem = get<4>(t); que.pop(); if (x == h - 1 && y == w - 1) { cout << a << endl; return 0; } for (int i = 0; i < 4; i++) { if (x + b1[i] < 0 || x + b1[i] >= h || y + b2[i] < 0 || y + b2[i] >= w)continue; if (z == 0) { if (!bo[i][x + b1[i]][y + b2[i]] && m[x][y] > m[x + b1[i]][y + b2[i]] && mem != m[x + b1[i]][y + b2[i]]) { que.push(make_tuple(a + 1, x + b1[i], y + b2[i], 1, m[x][y])); bo[i][x + b1[i]][y + b2[i]] = true; } } else { if (!bo[i][x + b1[i]][y + b2[i]] && m[x][y] < m[x + b1[i]][y + b2[i]] && mem != m[x + b1[i]][y + b2[i]]) { que.push(make_tuple(a + 1, x + b1[i], y + b2[i], 0, m[x][y])); bo[i][x + b1[i]][y + b2[i]] = true; } } } } cout << -1 << endl; }