結果

問題 No.629 グラフの中に眠る門松列
ユーザー CreativeGP1CreativeGP1
提出日時 2018-02-23 23:32:34
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,494 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-18 10:40:18
合計ジャッジ時間 6,952 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python
# -*- coding: utf-8 -*-

def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[args] = f(*args)
        return cache[args]
    return helper

import sys
import copy
from operator import itemgetter
import itertools
from time import sleep
import random


@memoize
def eval(a, b, c):
    if a == b or b == c or a == c: return False
    return max(a, b, c) == b or min(a, b, c) == b

l = sys.stdin.readline().split(' ')
N = int(l[0])
M = int(l[1])
a = []
l = sys.stdin.readline().split(' ')
path = {}
can = []
for i in xrange(N):
    a.append(int(l[i]))
    path[i+1] = []
    can.append([i+1])
u = []
v = []
for i in xrange(M):
    l = sys.stdin.readline().split(' ')
    u.append(int(l[0]))
    v.append(int(l[1]))


for i, j in zip(u, v):
    path[i].append(j)
    path[j].append(i)

print(path)
count = 0
while True:
    count += 1
    if len(can) == 0: break
    if count > N*N: break
    newcan = []
    for c in can:
        if len(c) == 3:
            if eval(a[c[0]-1], a[c[1]-1], a[c[2]-1]):
                print "YES"
                sys.exit(0)
        else:
            try:
                p = random.choice(path[c[-1]])
                c.append(p)
                newcan.append([p])
                # del path[c[-2]][0]
                newcan.append(c)
            except IndexError: pass
    newcan.sort()
    if can == newcan: break
    can = list(newcan for newcan,_ in itertools.groupby(newcan))

print "NO"
0