結果

問題 No.1370 置換門松列
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-12 15:05:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,603 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 82,264 KB
実行使用メモリ 110,972 KB
最終ジャッジ日時 2024-04-25 17:06:38
合計ジャッジ時間 4,798 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,060 KB
testcase_01 AC 38 ms
52,956 KB
testcase_02 AC 36 ms
53,288 KB
testcase_03 AC 37 ms
53,820 KB
testcase_04 AC 37 ms
52,532 KB
testcase_05 WA -
testcase_06 AC 38 ms
53,668 KB
testcase_07 AC 37 ms
53,464 KB
testcase_08 WA -
testcase_09 AC 37 ms
52,624 KB
testcase_10 WA -
testcase_11 AC 39 ms
53,240 KB
testcase_12 AC 37 ms
53,488 KB
testcase_13 AC 38 ms
53,484 KB
testcase_14 AC 37 ms
53,064 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 38 ms
54,328 KB
testcase_18 AC 38 ms
52,788 KB
testcase_19 AC 38 ms
52,784 KB
testcase_20 AC 41 ms
52,712 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 64 ms
87,928 KB
testcase_25 WA -
testcase_26 AC 154 ms
110,972 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
def main1(n,m,a):
  # 自明な例を除外
  for i in range(n-2):
    if a[i]!=a[i+1]!=a[i+2]!=a[i]:
      continue
    return []

  g=[[] for _ in range(m)]
  v0ls=set(range(m))
  for i in range(0,n,2):
    if 0<=i-1:
      u,v=a[i],a[i-1]
      u,v=u-1,v-1
      g[u].append(v)
      v0ls.discard(v)
    if i+m<n:
      u,v=a[i],a[i+1]
      u,v=u-1,v-1
      g[u].append(v)
      v0ls.discard(v)
  # u->vに辺がある<=>u<vが成り立つ必要がある。
  # グラフに循環がなければOK
  # 循環をチェック
  # 入次数0の頂点が一つもないとき、グラフは循環している。
  if len(v0ls)==0:return []
  
  # 出次数0の頂点に大きい値を入れる。重複がないようにする。
  ret=[-1]*m
  vl=[m]
  for v in range(m):
    if len(g[v])==0:
      ret[v]=vl[0]
      vl[0]-=1

  mi=set(range(m))
  seen=[0]*m
  def dfs(v):# 頂点vの値を決める。vから出ている辺があれば、その辺の先の頂点を先に決める。
    dfsret=True
    if ret[v]!=-1:return True
    for nv in g[v]:
      if seen[nv]==1:
        return False
      seen[nv]=1
      dfsret&=dfs(nv)
      seen[nv]=0
    ret[v]=vl[0]
    vl[0]-=1
    return dfsret
  lp=True
  for v0 in v0ls:
    lp&=dfs(v0)
  if not lp:return []
  return ret
  if chk(n,m,a,ret):
    return [x-mnv+1 if x is not None else 1 for x in ret]
  else:
    return []
if __name__=='__main__':
  n,m=map(int,input().split())
  a=list(map(int,input().split()))
  ret1=main1(n,m,a)
  if ret1:
    print('Yes')
    print(*ret1)
  else:
    print('No')

0