結果

問題 No.1369 交換門松列・竹
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-12 11:07:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 334 ms / 2,000 ms
コード長 1,170 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 84,176 KB
最終ジャッジ日時 2023-09-26 10:36:42
合計ジャッジ時間 7,662 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,432 KB
testcase_01 AC 72 ms
71,280 KB
testcase_02 AC 73 ms
71,132 KB
testcase_03 AC 71 ms
71,464 KB
testcase_04 AC 70 ms
71,040 KB
testcase_05 AC 70 ms
71,260 KB
testcase_06 AC 68 ms
71,260 KB
testcase_07 AC 90 ms
75,828 KB
testcase_08 AC 71 ms
71,272 KB
testcase_09 AC 85 ms
76,072 KB
testcase_10 AC 86 ms
75,972 KB
testcase_11 AC 73 ms
75,320 KB
testcase_12 AC 70 ms
71,292 KB
testcase_13 AC 220 ms
80,648 KB
testcase_14 AC 218 ms
80,836 KB
testcase_15 AC 121 ms
82,456 KB
testcase_16 AC 139 ms
82,424 KB
testcase_17 AC 141 ms
82,540 KB
testcase_18 AC 158 ms
82,444 KB
testcase_19 AC 142 ms
82,392 KB
testcase_20 AC 333 ms
82,224 KB
testcase_21 AC 139 ms
82,224 KB
testcase_22 AC 334 ms
82,204 KB
testcase_23 AC 159 ms
82,372 KB
testcase_24 AC 98 ms
81,448 KB
testcase_25 AC 210 ms
77,732 KB
testcase_26 AC 238 ms
77,772 KB
testcase_27 AC 239 ms
77,968 KB
testcase_28 AC 97 ms
81,116 KB
testcase_29 AC 101 ms
80,976 KB
testcase_30 AC 104 ms
84,176 KB
testcase_31 AC 97 ms
84,052 KB
testcase_32 AC 160 ms
77,888 KB
testcase_33 AC 154 ms
81,956 KB
権限があれば一括ダウンロードができます

ソースコード

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)>6:return 'No'
  # 門松になっていない箇所だけ探索する。
  for x in ary:
    for y in (x,x+1,x+2):
      for z in range(n):
        if a[z]==a[y]:continue
        # y,zを入れ替える
        a[y],a[z]=a[z],a[y]
        # 入れ替えた周辺ともともと門松でない箇所が門松になっているか。
        # iを変えると、i-2始まりの3要素、i-1始まりの3要素、i始まりの3要素、が影響を受ける。
        flg=True
        for i in ary+[y-2,y-1,y,z-2,z-1,z]:
          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(ret1)
0