結果

問題 No.1919 Many Monster Battles
ユーザー とりゐとりゐ
提出日時 2022-04-04 00:37:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 214,580 KB
最終ジャッジ日時 2024-06-11 20:26:37
合計ジャッジ時間 12,100 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
inv2=pow(2,mod-2,mod)

def f(x):
  y=sorted(x)
  res=0
  sm=0
  for i in range(n):
    y[i]%=mod
    res+=i*y[i]-sm
    res%=mod
    sm+=y[i]
    sm%=mod
  return res

def g(x,y):
  u,v=[],[]
  for i in range(n):
    u.append(x[i]-y[i])
    v.append(x[i]+y[i])
  return (f(u)+f(v))*inv2%mod

m=2*10**9
a1=[(m+1)*i for i in a]
a2=[m*i for i in a]
b1=[(m+1)*i for i in b]
b2=[m*i for i in b]

num1=g(a,b)
num2=g(a2,b1)
num3=g(a1,b2)
num4=g(a2,b2)

ans1=num1-num2+num4
ans2=num1-num3+num4
print(2*ans1%mod,2*ans2%mod)
0