結果

問題 No.1369 交換門松列・竹
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-12 10:59:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,180 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 71,652 KB
最終ジャッジ日時 2023-09-26 10:27:23
合計ジャッジ時間 5,358 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main1(n,a):
  ary=[]
  cnt=0
  for i in range(n-2):
    if a[i]!=a[i+1]!=a[i+2]!=a[i]:
      if a[i]>a[i+1]<a[i+2] or a[i]<a[i+1]>a[i+2]:
        continue
    ary.append(i)
  if len(ary)>5:return 'No'
  # 門松になっていない箇所だけ探索する。
  for x in ary:
    for y in (x,x+1,x+2):
      for z in range(n):
        # y,zを入れ替える
        a[y],a[z]=a[z],a[y]
        # 入れ替えた周辺ともともと門松でない箇所がが門松になっているか。
        # iを変えると、i-2始まりの3要素、i-1始まりの3要素、i始まりの3要素、が影響を受ける。
        flg=True
        for idx in ary+[y,z]:
          for i in (idx-2,idx-1,idx):
            if i<0 or n-2<=i:continue
            if a[i]!=a[i+1]!=a[i+2]!=a[i]:
              if a[i]>a[i+1]<a[i+2] or a[i]<a[i+1]>a[i+2]:
                continue
            flg=False
        a[y],a[z]=a[z],a[y]
        if flg:return 'Yes'
  return 'No'

if __name__=='__main_':
  t=int(input())
  cases=[]
  for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    cases.append((n,a))
  for n,a in cases:
    ret1=main1(n,a)
    print(ret0,ret1)
0