結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー tktk_snsn
提出日時 2021-11-26 23:23:13
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 992 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 55,544 KB
最終ジャッジ日時 2024-06-29 19:03:55
合計ジャッジ時間 8,023 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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):
    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