結果

問題 No.13 囲みたい!
ユーザー
提出日時 2021-02-04 21:36:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,402 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 101,972 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-01 03:06:58
合計ジャッジ時間 1,826 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0