結果
| 問題 | No.124 門松列(3) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-02-23 21:30:43 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,890 bytes | 
| コンパイル時間 | 873 ms | 
| コンパイル使用メモリ | 102,192 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-09-22 15:45:07 | 
| 合計ジャッジ時間 | 1,855 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 21 WA * 5 | 
ソースコード
#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[110][110] = { false }, bo1[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;
	bo[0][0] = true, bo1[0][0] = true;
	if (m[0][0] < m[0][1]) {
		que.push(make_tuple(1, 0, 1, 0, m[0][0]));
		bo[0][1] = true;
	}
	if (m[0][0] > m[0][1]) {
		que.push(make_tuple(1, 0, 1, 1, m[0][0]));
		bo1[0][1] = true;
	}
	if (m[0][0] < m[1][0]) {
		que.push(make_tuple(1, 1, 0, 0, m[0][0]));
		bo[1][0] = true;
	}
	if (m[0][0] < m[1][0]) {
		que.push(make_tuple(1, 1, 0, 1, m[0][0]));
		bo1[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 (!bo1[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]));
					bo1[x + b1[i]][y + b2[i]] = true;
				}
			}
			else {
				if (!bo[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[x + b1[i]][y + b2[i]] = true;
				}
			}
		}
	}
	cout << -1 << endl;
}
            
            
            
        