結果

問題 No.1369 交換門松列・竹
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-12 11:00:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,176 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 84,684 KB
最終ジャッジ日時 2023-09-26 10:28:34
合計ジャッジ時間 5,956 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,364 KB
testcase_01 AC 81 ms
75,256 KB
testcase_02 AC 77 ms
75,616 KB
testcase_03 AC 76 ms
75,288 KB
testcase_04 AC 77 ms
75,544 KB
testcase_05 AC 71 ms
71,304 KB
testcase_06 AC 70 ms
71,260 KB
testcase_07 AC 71 ms
71,292 KB
testcase_08 AC 75 ms
75,452 KB
testcase_09 AC 90 ms
76,348 KB
testcase_10 AC 71 ms
71,396 KB
testcase_11 AC 78 ms
75,496 KB
testcase_12 AC 77 ms
75,140 KB
testcase_13 AC 246 ms
80,704 KB
testcase_14 AC 229 ms
80,376 KB
testcase_15 AC 134 ms
82,632 KB
testcase_16 AC 163 ms
82,724 KB
testcase_17 AC 162 ms
82,312 KB
testcase_18 AC 164 ms
82,908 KB
testcase_19 AC 136 ms
82,700 KB
testcase_20 AC 86 ms
81,784 KB
testcase_21 AC 133 ms
82,536 KB
testcase_22 AC 86 ms
81,548 KB
testcase_23 AC 161 ms
82,504 KB
testcase_24 AC 84 ms
81,788 KB
testcase_25 AC 197 ms
77,812 KB
testcase_26 AC 239 ms
77,712 KB
testcase_27 AC 215 ms
77,568 KB
testcase_28 AC 83 ms
81,140 KB
testcase_29 AC 83 ms
81,136 KB
testcase_30 AC 86 ms
84,684 KB
testcase_31 AC 84 ms
84,084 KB
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(ret1)
0