結果

問題 No.3605 Grand Cross
コンテスト
ユーザー まぬお
提出日時 2026-07-31 22:58:08
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 1,463 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 232 ms
コンパイル使用メモリ 96,116 KB
実行使用メモリ 320,096 KB
最終ジャッジ日時 2026-07-31 22:58:29
合計ジャッジ時間 20,320 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right, insort
from itertools import permutations, combinations, groupby
from heapq import heappop, heappush
import math, sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
def printl(li, sep=" "): print(sep.join(map(str, li)))
def yn(flag): print(Yes if flag else No)
_int = lambda x: int(x)-1
MOD = 998244353 #10**9+7
INF = 1<<60
Yes, No = "Yes", "No"

for _ in range(int(input())):
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    D = list(map(int, input().split()))
    cumX = [0]
    for a in A: cumX.append(cumX[-1]+a)
    cumY = [0]
    for b in B: cumY.append(cumY[-1]+b)

    def check(m):
        colX = defaultdict(lambda:-INF)
        for i in range(m-1, N-m+1):
            val = cumX[i+m]-cumX[i-m+1]
            colX[C[i]] = max(colX[C[i]], val)
        colY = defaultdict(lambda:-INF)
        for i in range(m-1, M-m+1):
            val = cumY[i+m]-cumY[i-m+1]
            colY[D[i]] = max(colY[D[i]], val)
        ans = -1
        for c in colX:
            x = colX[c]
            y = colY[c]
            ans = max(ans, x+y)
        return ans

    l, r = 0, N+1
    while r-l>2:
        d = (r-l)//3
        m1 = l+d
        m2 = l+d+d
        if check(m1) < check(m2): l = m1
        else: r = m2
    m = (l+r)//2
    print(check(m))


0