結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,584 KB
testcase_01 AC 28 ms
8,852 KB
testcase_02 AC 28 ms
8,804 KB
testcase_03 AC 29 ms
8,864 KB
testcase_04 AC 28 ms
8,872 KB
testcase_05 AC 28 ms
8,808 KB
testcase_06 AC 286 ms
21,536 KB
testcase_07 AC 298 ms
29,656 KB
testcase_08 AC 280 ms
26,172 KB
testcase_09 AC 280 ms
20,840 KB
testcase_10 AC 301 ms
30,500 KB
testcase_11 AC 349 ms
31,952 KB
testcase_12 AC 287 ms
30,704 KB
testcase_13 AC 316 ms
31,208 KB
testcase_14 AC 287 ms
30,820 KB
testcase_15 AC 315 ms
31,804 KB
testcase_16 AC 400 ms
54,160 KB
testcase_17 AC 403 ms
54,168 KB
testcase_18 AC 402 ms
54,264 KB
testcase_19 AC 311 ms
51,816 KB
testcase_20 AC 300 ms
51,856 KB
testcase_21 AC 18 ms
8,516 KB
testcase_22 AC 18 ms
8,716 KB
testcase_23 AC 20 ms
8,520 KB
testcase_24 WA -
testcase_25 AC 295 ms
53,656 KB
testcase_26 AC 230 ms
44,196 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):
    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