結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  Bantako | 
| 提出日時 | 2018-06-14 19:09:26 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 13 ms / 5,000 ms | 
| コード長 | 1,329 bytes | 
| コンパイル時間 | 1,519 ms | 
| コンパイル使用メモリ | 168,992 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-30 14:26:08 | 
| 合計ジャッジ時間 | 2,512 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
コンパイルメッセージ
main.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main(){
      | ^~~~
            
            ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;    
int W,H;
int M[100][100];
bool dfs(P post,P now,int value){
    //cout << now.first << "," << now.second << endl;
    //cout << M[now.first][now.second] << endl;
    M[now.first][now.second] = -value;
    int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};
    rep(i,0,4){
        int x = dx[i] + now.second, y = dy[i] + now.first;
        //範囲外
        if(x < 0 || x >= W || y < 0 || y >= H)continue;
        //直前のマスには移動しない
        if(post.first == y && post.second == x)continue;
        //直前のマス以外でぶつかるところを探す
        if(M[y][x] == -value)return 1;
        if(M[y][x] == value && dfs(now, P(y,x), value))return 1;
    }
    return 0;
}
main(){
    cin >> W >> H;
    rep(i,0,H)rep(j,0,W)cin >> M[i][j];
    rep(k,1,1001)rep(i,0,H)rep(j,0,W){
        if(M[i][j] == k){
            //cout << i << " " << j << endl;
            if(dfs( P(-1,-1), P(i,j) , k)){
                cout << "possible" << endl;
                return 0;
            }
        }
    }
    /*
    rep(i,0,H)rep(j,0,W){
        cout << M[i][j] << " \n"[j == W-1];
    }
    */
    cout << "impossible" << endl;
}
            
            
            
        