#P9218. 「TAOI-1」Apollo

    ID: 10158 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>O2优化深度优先搜索 DFS最近公共祖先 LCA进制字典树 Trie单调栈

「TAOI-1」Apollo

Background

Execution.

This problem was originally called std::cout << std::fixed << std::setprecision(1) << 6.5 << '\n';.

[The picture deleted by the person involved.jpg]

【Upd 2023/04/15 21:42】A set of hack testdata was added in Subtask 2, #13. Now, in theory, all 50\bm{50}-point submissions during the contest can only get 30\bm{30} points.

Problem Description

You are given nn decimal numbers a1ana_1 \dots a_n.

For a number aa, define its precision f(a)f(a) as the smallest non-negative integer kk such that 10k×a10^k \times a is an integer. For an integer aa, define f(a)=0f(a) = 0. For two decimal numbers a,ba, b, define g(a,b)g(a, b) as the minimum value of f(c)f(c) over all numbers c[min(a,b),max(a,b)]c \in [\min(a,b), \max(a,b)].

For all 1in1 \leq i \leq n, you need to compute and output the value of j=1ng(ai,aj)\sum\limits_{j=1}^n g(a_i, a_j).

A decimal number is defined as a number that has an integer part and a fractional part, and whose fractional part is not 00. The reason it is described in such a silly way is that the input guarantees every number has a decimal point, but it seems no matter how it is written, someone will complain. Sorry about that. So I still have to look at the picture deleted by the person involved. So if I write some nonsense here, can anyone see it.

Input Format

The first line contains an integer nn.

The next nn lines each contain a decimal number aia_i.

Output Format

Output nn lines. Each line contains an integer, representing the answer for i=1ni = 1 \dots n.

5
11.4514
11.4778
11.1338
11.1236
11.4789
10
11
9
9
11
8
1.1145
1.114
1.1145
1.514
1.19198
1.1154
1.114
1.1145
24
21
24
10
18
22
21
24

Hint

Constraints

This problem uses bundled tests.

Let i=1nf(ai)=t\sum\limits_{i=1}^n f(a_i) = t.

  • Subtask 1 (15 points): ai10a_i \leq 10, n5n \leq 5, t10t \leq 10.
  • Subtask 2 (15 points): ai10a_i \leq 10, n100n \leq 100, t1000t \leq 1000.
  • Subtask 3 (20 points): n1722n \leq 1722.
  • Subtask 4 (15 points): ai1a_i \leq 1.
  • Subtask 5 (35 points): No special constraints.

For all testdata, 0<ai<1090 \lt a_i \lt 10^9, 1n1051 \leq n \leq 10^5, 1t3×1061 \leq t \leq 3 \times 10^6, it is guaranteed that ai\bm{a_i} has no trailing 0\color{black}\bm 0, and it is not guaranteed that ai\bm{a_i} are pairwise distinct.

Sample Explanation

Take i=1i = 1 as an example:

  • j=1j = 1: take c=11.4514c = 11.4514, f(c)=4f(c) = 4.
  • j=2j = 2: take c=11.46c = 11.46, f(c)=2f(c) = 2.
  • j=3j = 3: take c=11.2c = 11.2, f(c)=1f(c) = 1.
  • j=4j = 4: take c=11.3c = 11.3, f(c)=1f(c) = 1.
  • j=5j = 5: take c=11.47c = 11.47, f(c)=2f(c) = 2.

Therefore, $\sum\limits_{j=1}^n g(a_1, a_j) = 4 + 2 + 1 + 1 + 2 = 10$. For the same jj, among all the cc given above, there may also be other different cc such that f(c)f(c) is also minimal.

Translated by ChatGPT 5