結果

問題 No.13 囲みたい!
ユーザー Gara Gara
提出日時 2023-03-02 23:18:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 5,424 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 198,436 KB
最終ジャッジ日時 2025-02-11 01:16:54
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////////////
/// Variables ///
///////////////////////////////////////////////////
#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)
#define REPll(x,n) for(ll int x=0;x<n;x++)
#define REP2(x,l,r) for(int x=l;x<r;x++)
#define REP2ll(x,l,r) for(ll int x=l;x<r;x++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const ll int MOD=1000000007;
const ll int MOD2=998244353;
const int INF=1<<30;
const ll int INF2=(ll)1<<60;
const double PI = 3.1415926535897932;
///////////////////////////////////////////////////
/// Debug Function ///
///////////////////////////////////////////////////
/* debug fucoverload
https://o-treetree.hatenablog.com/entry/2020/06/11/220242
debug(a,b,c): a,b,c.
DEBUG,lDEBUG:
*/
namespace /* debug */{
#define DEBUG(...) do{cout<<#__VA_ARGS__<<" = "; debug(__VA_ARGS__);}while(0) //
#define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "; debug(__VA_ARGS__);}while(0) //
#define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = "; debug(__VA_ARGS__);}while(0) //,
template <class T> void show(T &x){cout<<x<<" ";}
template <class T> void showendl(T &x){cout<<x<<endl;}
template <class P, class Q> void show(pair<P, Q> &x){cout<<"("<<x.first<<", "<<x.second<<") ";}
template <class P, class Q> void showendl(pair<P, Q> &x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;}
template <class H> void debug(H&& h){showendl(h);}
template <class H, class... Ts> void debug(H&& h, Ts&&... ts){show(h);debug(forward<Ts>(ts)...);}
template <class T> void debug(vector<T> &vt){int i=0;int size = vt.size();for(auto x: vt)++i!=size ? show(x) : showendl(x);}
template <class T> void debug(vector<vector<T>> &vt){int i=0;int size = vt.size();for(int k=0; k<size; k++){int size_k = vt[k].size();for(auto x:
        vt[k])++i!=size_k ? show(x) : showendl(x);i=0;}}
template <class T> void debug(deque<T> &vt){int i=0;int size = vt.size();for(auto x: vt)++i!=size ? show(x) : showendl(x);}
template <class T> void debug(stack<T> s){int i=0;int size = s.size();while(!s.empty()){T w = s.top();++i!=size ? show(w) : showendl(w);s.pop
        ();}}
template <class T> void debug(queue<T> s){int i=0;int size = s.size();while(!s.empty()){T w = s.front();++i!=size ? show(w) : showendl(w);s.pop
        ();}}
template <class T> void debug(priority_queue<T> s){int i=0;int size = s.size();while(!s.empty()){T w = s.top();++i!=size ? show(w) : showendl(w
        );s.pop();}}
template <class T> void debug(set<T> s){int i=0;int size = s.size();for(auto x: s)++i!=size ? show(x) : showendl(x);}
template <class T> void debug(multiset<T> s){int i=0;int size = s.size();for(auto x: s)++i!=size ? show(x) : showendl(x);}
}
///////////////////////////////////////////////////
/// Function / Library ///
///////////////////////////////////////////////////
// a^b // O(logb)
ll intpow(ll a,ll b){ ll ans = 1; while(b){if(b & 1) {ans *= a;} a *= a; b /= 2;}return ans;}
// a^b mod p // O(logb)
ll modpow(ll a, ll b, ll p){ll ans = 1; while(b){if(b & 1) {(ans *= a) %= p;} (a *= a) %= p; b /= 2;}return ans;}
// %
ll mod(ll val, ll m) {ll res = val % m; if (res < 0) res += m; return res;}
// mod. m a a^{-1} : gcd(a, m) = 1
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0; while (b) {ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v);} u %= m; if (u < 0) u += m;
    return u;}
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
// vector // O()
template<class T> vector<ll int> num_digit (T a){string ss = to_string(a);int size = ss.size();vector<ll int> v(size);for(int i=0; i<size; i++){v[i]
    = ss[i] - '0';}return v;}
template<class T> ll int digit_length(T a){string ss = to_string(a);return (ll int)ss.size();}
// gcd() // O(log(min(a,b)))
ll int gcd(ll int a, ll int b){if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}
// lcm// O(log(min(a,b)))
ll int lcm(ll int a, ll int b){return a / gcd(a, b) * b;}
/////////////////////////////////////////////////////////////
// task.jsonwall-optionbuild
int main (){
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
int W, H; cin >> W >> H;
vector<vector<int>> M(H, vector<int>(W));
REP(i,H){
REP(j,W){
cin >> M[i][j];
}
}
vector<vector<int>> dist(H, vector<int>(W, -1));
int f = 0;
auto dfs = [&](auto&& self, int i, int j, int m, int pi, int pj) -> void{
if(f) return;
if(dist[i][j] != -1){
f = 1;
return ;
}
dist[i][j] = 1;
if(i > 0){
if(M[i-1][j]==m && i-1!=pi) self(self, i-1, j, m, i, j);
}
if(i < H-1){
if(M[i+1][j]==m && i+1!=pi) self(self, i+1, j, m, i, j);
}
if(j > 0){
if(M[i][j-1]==m && j-1!=pj) self(self, i, j-1, m, i, j);
}
if(j < W-1){
if(M[i][j+1]==m && j+1!=pj) self(self, i, j+1, m, i, j);
}
return;
};
REP(i,H){
REP(j,W){
// debug(dist);
// debug("--------");
if(dist[i][j]==-1){
dfs(dfs, i, j, M[i][j], -1, -1);
}
}
}
if(f) cout << "possible" << endl;
else cout << "impossible" << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0