結果

問題 No.488 四角関係
ユーザー t8m8⛄️t8m8⛄️
提出日時 2017-04-28 13:06:44
言語 Nim
(2.0.0)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 1,136 bytes
コンパイル時間 3,174 ms
コンパイル使用メモリ 68,696 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 12:47:18
合計ジャッジ時間 5,233 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,376 KB
testcase_01 AC 30 ms
4,376 KB
testcase_02 AC 26 ms
4,384 KB
testcase_03 AC 11 ms
4,376 KB
testcase_04 AC 18 ms
4,376 KB
testcase_05 AC 49 ms
4,376 KB
testcase_06 AC 28 ms
4,376 KB
testcase_07 AC 133 ms
4,376 KB
testcase_08 AC 142 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils

var start = -1

proc f(g: seq[seq[int]]; i, j, k, l: var int, cur: int, a: seq[int]): bool =
  var flag = i >= 0 and j >= 0 and k >= 0 and l >= 0 
  if flag: start = cur
  if cur == i: i = -1
  if cur == j: j = -1
  if cur == k: k = -1
  if cur == l: l = -1
  if i < 0 and j < 0 and k < 0 and l < 0:
    if start in g[cur]: return true
    else: return false
  var
    next = -1
    cnt = 0
  for to in g[cur]:
    if to in [i, j, k, l]:
      if next < 0:
        next = to
    if to in a: cnt.inc
  if cnt > 2: return false
  if next < 0: return false
  return f(g, i, j, k, l, next, a)
  

when isMainModule:
  var
    input = stdin.readline.split.map(parseint)
    (n, m) = (input[0], input[1])
    g = newSeqWith(n, newSeq[int]())
  
  for i in 0..m-1:
    var
      e = stdin.readline.split.map(parseint)
      (a, b) = (e[0], e[1])
    g[a].add(b)
    g[b].add(a)
  
  var ans = 0
  
  for i in 0..n-1:
    for j in i+1..n-1:
      for k in j+1..n-1:
        for l in k+1..n-1:
          var (I, J, K, L) = (i, j, k, l)
          if f(g, I, J, K, L, i, @[i, j, k, l]):
            ans.inc
  
  echo ans
0