結果
| 問題 | No.1950 片道きゃっちぼーる |
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2022-05-20 21:46:25 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 634 ms / 3,000 ms |
| コード長 | 1,406 bytes |
| 記録 | |
| コンパイル時間 | 167 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 182,632 KB |
| 最終ジャッジ日時 | 2024-09-20 07:45:45 |
| 合計ジャッジ時間 | 9,712 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
import sys
# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353
n = II()
xx = LI()
aa = LI()
um = []
ux = []
xtou = {}
for u, (x, a) in enumerate(zip(xx, aa)):
mx = x+a
um.append((u, mx))
ux.append((u, x))
xtou[x] = u
r = -1
to = [[] for _ in range(n)]
for u,x in enumerate(xx):
y=x+aa[u]
if y in xtou:
v=xtou[y]
to[v].append(u)
y=x-aa[u]
if y in xtou:
v=xtou[y]
to[v].append(u)
um.sort(key=lambda x: -x[1])
ans = [-1]*n
for u, mx in um:
if ans[u] != -1: continue
st = [u]
ans[u] = mx-xx[u]
while st:
u = st.pop()
for v in to[u]:
if ans[v] != -1: continue
ans[v] = mx-xx[v]
st.append(v)
for a in ans: print(a)
mkawa2