結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー tktk_snsntktk_snsn
提出日時 2021-11-26 23:24:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,051 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 11,040 KB
実行使用メモリ 54,316 KB
最終ジャッジ日時 2023-09-12 05:58:58
合計ジャッジ時間 6,716 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,552 KB
testcase_01 AC 28 ms
8,968 KB
testcase_02 AC 31 ms
8,964 KB
testcase_03 AC 30 ms
9,008 KB
testcase_04 AC 27 ms
8,900 KB
testcase_05 AC 28 ms
8,904 KB
testcase_06 AC 304 ms
22,956 KB
testcase_07 AC 257 ms
29,612 KB
testcase_08 AC 286 ms
26,112 KB
testcase_09 AC 215 ms
21,728 KB
testcase_10 AC 293 ms
30,868 KB
testcase_11 AC 370 ms
32,100 KB
testcase_12 AC 306 ms
32,228 KB
testcase_13 AC 254 ms
31,108 KB
testcase_14 AC 135 ms
27,936 KB
testcase_15 AC 256 ms
31,848 KB
testcase_16 AC 426 ms
54,316 KB
testcase_17 AC 427 ms
54,132 KB
testcase_18 AC 429 ms
54,228 KB
testcase_19 AC 153 ms
37,892 KB
testcase_20 AC 154 ms
37,880 KB
testcase_21 AC 18 ms
8,740 KB
testcase_22 AC 17 ms
8,692 KB
testcase_23 AC 20 ms
8,612 KB
testcase_24 WA -
testcase_25 AC 306 ms
53,576 KB
testcase_26 AC 126 ms
35,632 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


def RunLengthEncoding(S):
    res = []
    N = len(S)
    i = 0
    while i < N:
        cnt = 1
        while i < N - 1 and S[i] == S[i + 1]:
            cnt += 1
            i += 1
        res.append(S[i])
        i += 1
    return res


def F(N, A, B):
    if not set(A).issuperset(set(B)):
        return False
    for i in range(N):
        if A[i] > B[i]:
            return False

    pos = defaultdict(list)
    for i, a in enumerate(A):
        pos[a].append(i)

    i = 0
    idx = defaultdict(int)
    for b in RunLengthEncoding(B):
        while idx[b] < len(pos[b]) and pos[b][idx[b]] < i:
            idx[b] += 1
        if idx[b] >= len(pos[b]):
            return False
        i = pos[b][idx[b]]
    return True


T = int(input())
for _ in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    if F(N, A, B):
        print("Yes")
    else:
        print("No")
0