結果

問題 No.13 囲みたい!
ユーザー 夜
提出日時 2021-02-04 21:36:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,402 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 101,140 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 18:27:48
合計ジャッジ時間 1,877 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
int m[110][110];
bool b[110][110] = { false };
int b1[4] = { 0,0,-1,1 };
int b2[4] = { -1,1,0,0 };
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];
		}
	}
	stack<tuple<int, int, int, int, int>> st;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (!b[i][j]) {
				b[i][j] = true;
				st.push(make_tuple(i, j, m[i][j], -1, -1));
			}
			while (!st.empty()) {
				tuple<int, int, int, int, int> t = st.top();
				st.pop();
				int x = get<0>(t);
				int y = get<1>(t);
				int num = get<2>(t);
				int ax = get<3>(t);
				int ay = get<4>(t);
				for (int i = 0; i < 4; i++) {
					if (x + b1[i] < 0 || y + b2[i] < 0 || x + b1[i] >= h || y + b2[i] >= w)continue;
					if (num == m[x + b1[i]][y + b2[i]]) {
						if (!b[x + b1[i]][y + b2[i]]) {
							st.push(make_tuple(x + b1[i], y + b2[i], num, x, y));
							b[x + b1[i]][y + b2[i]] = true;
						}
						else if (ax != x + b1[i] || ay != y + b2[i]) {
							cout << "possible" << endl;
							return 0;
						}
					}
				}
			}
		}
	}
	cout << "impossible" << endl;
}

0