結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-11-26 23:57:01
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,317 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 131,740 KB
最終ジャッジ日時 2023-09-12 06:04:39
合計ジャッジ時間 8,724 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,208 KB
testcase_01 AC 139 ms
77,928 KB
testcase_02 AC 162 ms
78,480 KB
testcase_03 AC 122 ms
77,508 KB
testcase_04 AC 126 ms
77,732 KB
testcase_05 AC 125 ms
77,424 KB
testcase_06 AC 329 ms
100,492 KB
testcase_07 AC 289 ms
98,244 KB
testcase_08 AC 285 ms
97,256 KB
testcase_09 AC 270 ms
97,040 KB
testcase_10 AC 280 ms
106,908 KB
testcase_11 AC 269 ms
107,100 KB
testcase_12 AC 274 ms
114,072 KB
testcase_13 AC 284 ms
113,656 KB
testcase_14 AC 268 ms
114,352 KB
testcase_15 AC 291 ms
115,404 KB
testcase_16 AC 243 ms
111,856 KB
testcase_17 AC 249 ms
111,812 KB
testcase_18 AC 243 ms
111,228 KB
testcase_19 AC 234 ms
111,280 KB
testcase_20 AC 238 ms
111,340 KB
testcase_21 AC 77 ms
71,140 KB
testcase_22 AC 78 ms
71,264 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 216 ms
131,740 KB
testcase_26 AC 219 ms
131,712 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from sys import stdin

tt = int(stdin.readline())

ANS = []
for loop in range(tt):

    N = int(stdin.readline())
    A = list(map(int,stdin.readline().split()))
    B = list(map(int,stdin.readline().split()))

    flag = True
    for i in range(N):
        if A[i] > B[i]:
            flag = False

    able = [False] * N
    stk = []
    stkset = set()
    
    for i in range(N):
        while len(stk) > 0 and stk[-1] <= A[i]:
            stkset.remove(stk[-1])
            del stk[-1]

        stk.append(A[i])
        stkset.add(A[i])
        if B[i] in stkset:
            able[i] = True

    A.reverse()
    B.reverse()

    stk = []
    stkset = set()
    
    for i in range(N):
        while len(stk) > 0 and stk[-1] <= A[i]:
            stkset.remove(stk[-1])
            del stk[-1]

        stk.append(A[i])
        stkset.add(A[i])
        if B[i] in stkset:
            able[N-1-i] = True

    A.reverse()
    B.reverse()

    if False in able:
        flag = False

    B2 = []
    for i in B:
        if len(B2) == 0 or B2[-1] != i:
            B2.append(i)

    for i in range(N-1,-1,-1):
        if len(B2) > 0 and B2[-1] == A[i]:
            del B2[-1]

    if B2:
        flag = False

    if flag:
        ANS.append("Yes")
    else:
        ANS.append("No")

print ("\n".join(ANS))
0