AT_arc231_a.Two Dimensional Invader

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

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

  • If you choose to defeat the monster with a sword, you move to point (Xi,Yi)(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 (Xi,Yi)(X_i, Y_i).
  • If you choose to defeat the monster with magic, a cost of ZiZ_i is incurred. In this case, you do not move.

Find the minimum total cost eventually required.

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

Solve TT test cases per input file.

你是一名位于二维平面上的魔法战士,初始位置为点 (0,0)(0, 0)。

接下来将发生 NN 个事件。在第 ii 个事件(1≤i≤N1 \leq i \leq N)中,一只怪物出现在点 (Xi,Yi)(X_i, Y_i),你需要选择用剑或魔法击败该怪物。

  • 若选择用剑击败怪物,则你需移动至点 (Xi,Yi)(X_i, Y_i)。此次移动产生的代价等于你移动前所在位置与点 (Xi,Yi)(X_i, Y_i) 之间的欧几里得距离的平方。
  • 若选择用魔法击败怪物,则产生代价 ZiZ_i;此时你无需移动。

求最终所需的最小总代价。

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

每组输入文件需解决 TT 个测试用例。

输入格式

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

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN
X1X_1 Y1Y_1 Z1Z_1
X2X_2 Y2Y_2 Z2Z_2
⋮\vdots
XNX_N YNY_N ZNZ_N

输入从标准输入中按以下格式给出。其中,casei\mathrm{case}_i(1≤i≤T1 \leq i \leq T)表示第 ii 个测试用例。

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例按以下格式给出:

NN
X1X_1 Y1Y_1 Z1Z_1
X2X_2 Y2Y_2 Z2Z_2
⋮\vdots
XNX_N YNY_N ZNZ_N

输出格式

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

输出 TT 行。第 ii 行(1≤i≤T1 \leq i \leq T)应包含 casei\mathrm{case}_i 的答案。

输入输出样例

  • 输入#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

    输出#1

    44
    231

说明/提示

Sample 1 Explanation:

  • 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)(0, 0) to point (0,4)(0, 4). This incurs a cost of 1616.
    • In the second event, a cost of 1111 is incurred.
    • In the third event, you move from point (0,4)(0, 4) to point (4,5)(4, 5). This incurs a cost of 1717.
  • The total cost eventually required is 16+11+17=4416 + 11 + 17 = 44.

Constraints

  • 1≤T≤101 \leq T \leq 10
  • 1≤N≤250 0001 \leq N \leq 250\,000
  • 0≤Xi<5000 \leq X_i < 500 (1≤i≤N1 \leq i \leq N)
  • 0≤Yi<5000 \leq Y_i < 500 (1≤i≤N1 \leq i \leq N)
  • 1≤Zi≤1091 \leq Z_i \leq 10^9 (1≤i≤N1 \leq i \leq N)
  • The sum of NN over the TT test cases is at most 250 000250\,000.
  • All input values are integers.

样例 1 解释:

  • 对于第一个测试用例,最优策略是在第一场和第三场事件中选择用剑击败怪物,在第二场事件中选择用魔法击败怪物。各事件的具体过程如下:
    • 在第一场事件中,你从点 (0,0)(0, 0) 移动到点 (0,4)(0, 4),产生代价 1616。
    • 在第二场事件中,产生代价 1111。
    • 在第三场事件中,你从点 (0,4)(0, 4) 移动到点 (4,5)(4, 5),产生代价 1717。
  • 最终所需的总代价为 16+11+17=4416 + 11 + 17 = 44。

约束条件

  • 1≤T≤101 \leq T \leq 10
  • 1≤N≤250 0001 \leq N \leq 250\,000
  • 0≤Xi<5000 \leq X_i < 500(1≤i≤N1 \leq i \leq N)
  • 0≤Yi<5000 \leq Y_i < 500(1≤i≤N1 \leq i \leq N)
  • 1≤Zi≤1091 \leq Z_i \leq 10^9(1≤i≤N1 \leq i \leq N)
  • 所有 TT 个测试用例的 NN 值之和不超过 250 000250\,000。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页