結果
| 問題 | No.3605 Grand Cross |
| コンテスト | |
| ユーザー |
ゼット
|
| 提出日時 | 2026-07-31 22:14:26 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,174 bytes |
| 記録 | |
| コンパイル時間 | 232 ms |
| コンパイル使用メモリ | 96,104 KB |
| 実行使用メモリ | 207,516 KB |
| 最終ジャッジ日時 | 2026-07-31 22:14:45 |
| 合計ジャッジ時間 | 19,110 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 WA * 19 |
ソースコード
Q=int(input())
for _ in range(Q):
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()))
Ga=[[] for i in range(N+M+1)]
Gb=[[] for i in range(N+M+1)]
result=-1
for i in range(N):
x=C[i]
Ga[x].append(i)
for i in range(M):
x=D[i]
Gb[x].append(i)
va=[0]*(N+1)
vb=[0]*(M+1)
for i in range(N):
va[i]=va[i-1]+A[i]
for i in range(M):
vb[i]=vb[i-1]+B[i]
for x in range(1,N+M+1):
if len(Ga[x])*len(Gb[x])==0:
continue
d=-1
for pos in Ga[x]:
if pos<N//2:
d=max(d,pos)
if d>=0:
s=va[2*d]
score=-10**20
for pos in Gb[x]:
l,r=pos-d,pos+d
if 0<=l<M and 0<=r<M:
ans=vb[r]-vb[l-1]
score=max(score,ans)
result=max(result,score+s)
d=-1
for pos in Ga[x]:
if pos>=N//2:
d=max(d,N-1-pos)
s=va[N-1]-va[N-1-(2*d+1)]
score=-10**20
if d>=0:
for pos in Gb[x]:
l,r=pos-d,pos+d
if 0<=l<M and 0<=r<M:
ans=vb[r]-vb[l-1]
score=max(score,ans)
result=max(result,score+s)
A,B=B,A
C,D=D,C
N,M=M,N
Ga=[[] for i in range(N+M+1)]
Gb=[[] for i in range(N+M+1)]
for i in range(N):
x=C[i]
Ga[x].append(i)
for i in range(M):
x=D[i]
Gb[x].append(i)
va=[0]*(N+1)
vb=[0]*(M+1)
for i in range(N):
va[i]=va[i-1]+A[i]
for i in range(M):
vb[i]=vb[i-1]+B[i]
for x in range(1,N+M+1):
if len(Ga[x])*len(Gb[x])==0:
continue
d=-1
for pos in Ga[x]:
if pos<N//2:
d=max(d,pos)
s=va[2*d]
score=-10**20
if d>=0:
for pos in Gb[x]:
l,r=pos-d,pos+d
if 0<=l<M and 0<=r<M:
ans=vb[r]-vb[l-1]
score=max(score,ans)
result=max(result,score+s)
d=-1
for pos in Ga[x]:
if pos>=N//2:
d=max(d,N-1-pos)
s=va[N-1]-va[N-1-(2*d+1)]
score=-10**20
if d>=0:
for pos in Gb[x]:
l,r=pos-d,pos+d
if 0<=l<M and 0<=r<M:
ans=vb[r]-vb[l-1]
score=max(score,ans)
result=max(result,score+s)
print(result)
ゼット