結果

問題 No.13 囲みたい!
ユーザー BantakoBantako
提出日時 2018-06-14 19:09:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,329 bytes
コンパイル時間 1,456 ms
コンパイル使用メモリ 165,388 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 04:12:18
合計ジャッジ時間 2,596 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 10 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 10 ms
4,380 KB
testcase_08 AC 10 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:27:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   27 | main(){
      | ^~~~

ソースコード

diff #

#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;
}
0