結果

問題 No.179 塗り分け
ユーザー kou_kkkkou_kkk
提出日時 2024-04-24 10:05:13
言語 Nim
(2.0.2)
結果
AC  
実行時間 248 ms / 3,000 ms
コード長 1,130 bytes
コンパイル時間 4,115 ms
コンパイル使用メモリ 67,456 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 10:05:20
合計ジャッジ時間 5,870 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 248 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 7 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 9 ms
5,376 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 11 ms
5,376 KB
testcase_34 AC 3 ms
5,376 KB
testcase_35 AC 13 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils, strutils, sugar

let
  xs = stdin.readLine.split.map parseInt
  h = xs[0]
  w = xs[1]
  ss = (0 ..< h).mapIt stdin.readLine


proc fn(s: string): seq[int] =
  collect newSeq:
    for i, c in s:
      if c == '#': i


let
  ss2 = ss.map fn
  idxs = collect newSeq:
    for i, xs in ss2:
      for x in xs: (i, x)
  length = idxs.len


proc sub(list: var seq[int], val: int): void =
  var idx = 0
  for i, v in list:
    if val == v: idx = i
  list.del idx


proc fn2(dist: (int, int)): bool =
  var
    xs = ss2
    cnt = 0
  for (i, j) in idxs:
    if j notin xs[i]: continue
    let
      i2 = i.succ dist[0]
      j2 = j.succ dist[1]
    if i2 < 0 or i2 >= h or j2 < 0 or j2 >= w: continue
    if j2 notin xs[i2]: return false
    sub(xs[i], j)
    sub(xs[i.succ dist[0]], j.succ dist[1])
    inc cnt
    if cnt == length div 2: return true


if length == 0 or length mod 2 == 1:
  echo "NO"
else:
  var
    b: bool
  let
    list = idxs[1 ..< length]
  for (i, j) in list:
    let dist = (i.pred idxs[0][0],j.pred idxs[0][1])
    b = fn2 dist
    if b:
      break

  if b:
    echo "YES"
  else:
    echo "NO"
0