Submission #69155294


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

/////////////////// メイン ///////////////////

int main () {
  
  //////////////////// 入力 ////////////////////

  int h, w;
  cin >> h >> w;

  vector<string> s(h);
  for (int i=0; i<h; i++) {
    cin >> s.at(i);
  }

  //////////////// 出力変数定義 ////////////////

  // "Yes"で初期化しておいて、条件を満たさないところが1つでもあったら"No"にする
  string result = "Yes";

  //////////////////// 処理 ////////////////////

  // グリッドを1マスずつ調べていく
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {

      // 白マスだったら、無条件にOKなので次へ
      if (s.at(i).at(j)=='.') continue;

      // 周りの黒マスの数を数える
      int counter = 0;
      if (i>0&&s.at(i-1).at(j)=='#') counter++;
      if (i<h-1&&s.at(i+1).at(j)=='#') counter++;
      if (j>0&&s.at(i).at(j-1)=='#') counter++;
      if (j<w-1&&s.at(i).at(j+1)=='#') counter++;

      // 2個でも4個でもなかったらNG
      if (counter!=2&&counter!=4) result = "No";

    }
  }

  //////////////////// 出力 ////////////////////

  cout << result << endl;

  //////////////////// 終了 ////////////////////

  return 0;

}

Submission Info

Submission Time
Task B - Looped Rope
User wightou
Language C++ 23 (gcc 12.2)
Score 200
Code Size 1302 Byte
Status AC
Exec Time 1 ms
Memory 3632 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 4
AC × 25
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 02_handmade_14.txt, 02_handmade_15.txt, 02_handmade_16.txt, 02_handmade_17.txt, 02_handmade_18.txt, 02_handmade_19.txt, 02_handmade_20.txt, 02_handmade_21.txt, 02_handmade_22.txt, 02_handmade_23.txt, 02_handmade_24.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3448 KiB
00_sample_01.txt AC 1 ms 3464 KiB
00_sample_02.txt AC 1 ms 3452 KiB
00_sample_03.txt AC 1 ms 3504 KiB
01_random_04.txt AC 1 ms 3452 KiB
01_random_05.txt AC 1 ms 3452 KiB
01_random_06.txt AC 1 ms 3540 KiB
01_random_07.txt AC 1 ms 3536 KiB
01_random_08.txt AC 1 ms 3448 KiB
01_random_09.txt AC 1 ms 3444 KiB
01_random_10.txt AC 1 ms 3436 KiB
01_random_11.txt AC 1 ms 3488 KiB
01_random_12.txt AC 1 ms 3448 KiB
01_random_13.txt AC 1 ms 3540 KiB
02_handmade_14.txt AC 1 ms 3336 KiB
02_handmade_15.txt AC 1 ms 3536 KiB
02_handmade_16.txt AC 1 ms 3440 KiB
02_handmade_17.txt AC 1 ms 3524 KiB
02_handmade_18.txt AC 1 ms 3632 KiB
02_handmade_19.txt AC 1 ms 3532 KiB
02_handmade_20.txt AC 1 ms 3336 KiB
02_handmade_21.txt AC 1 ms 3340 KiB
02_handmade_22.txt AC 1 ms 3512 KiB
02_handmade_23.txt AC 1 ms 3344 KiB
02_handmade_24.txt AC 1 ms 3480 KiB