結果

問題 No.13 囲みたい!
ユーザー yuppe19 😺yuppe19 😺
提出日時 2017-06-18 14:42:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 560 ms / 5,000 ms
コード長 1,455 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 83,620 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 19:45:54
合計ジャッジ時間 2,491 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 560 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 137 ms
6,944 KB
testcase_08 AC 112 ms
6,940 KB
testcase_09 AC 110 ms
6,940 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 49 ms
6,944 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 29 ms
6,944 KB
testcase_14 AC 36 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |   int C, R; scanf("%d%d", &C, &R);
      |             ~~~~~^~~~~~~~~~~~~~~~
main.cpp:17:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |       scanf("%d", &G[r][c]);
      |       ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <array>
#include <queue>
#include <tuple>
using namespace std;
                            // N  E  S  W
constexpr array<int, 4> dr = {-1, 0, 1, 0},
                        dc = { 0, 1, 0,-1};
constexpr int dr_size = dr.size();

int main(void) {
  int C, R; scanf("%d%d", &C, &R);
  vector<vector<int>> G(R, vector<int>(C, 0)); // G[R][C]
  for(int r=0; r<R; ++r) {
    for(int c=0; c<C; ++c) {
      scanf("%d", &G[r][c]);
    }
  }
  for(int r=0; r<R; ++r) { // (r, c) := 始点
    for(int c=0; c<C; ++c) {
      int val = G[r][c];
      vector<vector<bool>> seen(R, vector<bool>(C, false)); // seen[R][C]
      queue<tuple<int, int, int, int>> que;
      // 今の座標、ひとつ前の座標
      que.emplace(r, c, -1, -1);
      while(!que.empty()) {
        int rr, cc, br, bc; tie(rr, cc, br, bc) = que.front(); que.pop();
        for(int i=0; i<dr_size; ++i) {
          int nr = rr + dr[i],
              nc = cc + dc[i];
          if(!(0 <= nr && nr < R && 0 <= nc && nc < C)) { continue; }
          if(G[nr][nc] != val) { continue; }
          if(nr == br && nc == bc) { continue; }
          if(seen[nr][nc]) { continue; }
          if(nr == r && nc == c) {
            puts("possible");
            return 0;
          }
          seen[nr][nc] = true;
          que.emplace(nr, nc, rr, cc);
          seen[nr][nc] = false;
        }
      }
    }
  }
  puts("impossible");
  return 0;
}
0