第 231 场 AtCoder Regular Contest
A
二维入侵者
Two Dimensional Invader
AtCoder
⌀ 1646
原题
←B →

二维入侵者AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are a magic warrior on a two-dimensional plane, initially located at point $(0, 0)$.

你是一名魔法战士,位于二维平面上的点 $(0, 0)$。AI (CI翻译)

$N$ events will now occur. In the $i$-th event ($1 \leq i \leq N$), one monster appears at point $(X_i, Y_i)$, and you choose whether to defeat this monster with a sword or with magic.

接下来会发生 $N$ 个事件。在第 $i$ 个事件($1 \leq i \leq N$)中,一个怪物会出现在点 $(X_i, Y_i)$,你需要选择用剑或魔法击败它。AI (CI翻译)

  • If you choose to defeat the monster with a sword, you move to point $(X_i, Y_i)$. This incurs a cost equal to the square of the Euclidean distance between the point where you were located before moving and point $(X_i, Y_i)$.
  • If you choose to defeat the monster with magic, a cost of $Z_i$ is incurred. In this case, you do not move.
  • 如果你选择用剑击败怪物,你会移动到点 $(X_i, Y_i)$。这会产生一笔费用,等于你移动前所在位置与点 $(X_i, Y_i)$ 之间的欧几里得距离的平方。
  • 如果你选择用魔法击败怪物,则会产生 $Z_i$ 的费用。这种情况下,你不会移动。
AI (CI翻译)

Find the minimum total cost eventually required.

求最终需要付出的最小总费用。AI (CI翻译)

What is Euclidean distance? The Euclidean distance between point $(a, b)$ and point $(c, d)$ is defined as $\sqrt{(a - c)^2 + (b - d)^2}$.

什么是欧几里得距离?点 $(a, b)$ 与点 $(c, d)$ 之间的欧几里得距离定义为 $\sqrt{(a - c)^2 + (b - d)^2}$。AI (CI翻译)

Solve $T$ test cases per input file.

每个输入文件包含 $T$ 组测试数据,请分别求解。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \leq T \leq 10$
  • $1 \leq N \leq 250\,000$
  • $0 \leq X_i < 500$ ($1 \leq i \leq N$)
  • $0 \leq Y_i < 500$ ($1 \leq i \leq N$)
  • $1 \leq Z_i \leq 10^9$ ($1 \leq i \leq N$)
  • The sum of $N$ over the $T$ test cases is at most $250\,000$.
  • All input values are integers.
  • $1 \leq T \leq 10$
  • $1 \leq N \leq 250\,000$
  • $0 \leq X_i < 500$($1 \leq i \leq N$)
  • $0 \leq Y_i < 500$($1 \leq i \leq N$)
  • $1 \leq Z_i \leq 10^9$($1 \leq i \leq N$)
  • $T$ 组测试数据中 $N$ 的总和不超过 $250\,000$。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format. Here, $\mathrm{case}_i$ ($1 \leq i \leq T$) denotes the $i$-th test case.

输入从标准输入读入,格式如下。其中,$\mathrm{case}_i$($1 \leq i \leq T$)表示第 $i$ 组测试数据。AI (CI翻译)

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
AI (CI翻译)

Each test case is given in the following format:

每组测试数据的格式如下:AI (CI翻译)

N
X_1 Y_1 Z_1
X_2 Y_2 Z_2
\vdots
X_N Y_N Z_N

N
X_1 Y_1 Z_1
X_2 Y_2 Z_2
\vdots
X_N Y_N Z_N
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $T$ lines. The $i$-th line ($1 \leq i \leq T$) should contain the answer for $\mathrm{case}_i$.

输出 $T$ 行。第 $i$ 行($1 \leq i \leq T$)应包含 $\mathrm{case}_i$ 的答案。AI (CI翻译)

样例

Input #1
2
3
0 4 28
2 9 11
4 5 26
7
6 0 96
0 2 54
9 0 36
0 7 81
6 5 91
2 8 71
7 6 40
Output #1
44
231
- For the first test case, it is optimal to choose to defeat the monster with a sword in the first and third events, and to choose to defeat the monster with magic in the second event. Each event proceeds as follows. - In the first event, you move from point $(0, 0)$ to point $(0, 4)$. This incurs a cost of $16$. - In the second event, a cost of $11$ is incurred. - In the third event, you move from point $(0, 4)$ to point $(4, 5)$. This incurs a cost of $17$. - The total cost eventually required is $16 + 11 + 17 = 44$.
题目信息
题号
arc231_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。