第七回日本最強プログラマー学生選手権-予選-(AtCoder Regular Contest 222)
D
移位与相加
Shift and Add
AtCoder
⌀ 2755
原题
← CE →

移位与相加AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

Define the digit sum of a non-negative integer $n$ as the sum of the digits when $n$ is written in decimal notation. For example, the digit sum of $2026$ is $2+0+2+6=10$.

将非负整数 $n$ 写成十进制表示时,将其各位数字之和定义为 $n$ 的数位和。例如,$2026$ 的数位和为 $2+0+2+6=10$。AI (CI翻译)

You are given positive integer sequences $A=(A_1,A_2,\ldots,A_N)$ and $B=(B_1,B_2,\ldots,B_N)$.

给定正整数序列 $A=(A_1,A_2,\ldots,A_N)$ 和 $B=(B_1,B_2,\ldots,B_N)$。AI (CI翻译)

Using $A$ and $B$, define an integer sequence $X=(X_0,X_1,X_2,\ldots,X_N)$ as follows:

使用 $A$ 和 $B$,按如下方式定义整数序列 $X=(X_0,X_1,X_2,\ldots,X_N)$:AI (CI翻译)

  • Set $X_0 = 0$.
  • For each $i=1,2,\ldots,N$, choose one of $X_i = 10X_{i-1} + A_i$ and $X_i = 10X_{i-1} + B_i$ to determine $X_i$.
  • 令 $X_0 = 0$。
  • 对于每个 $i=1,2,\ldots,N$,从 $X_i = 10X_{i-1} + A_i$ 和 $X_i = 10X_{i-1} + B_i$ 中选择一个,以确定 $X_i$。
AI (CI翻译)

For each $k=1,2,\ldots,N$, find the minimum possible digit sum of $X_k$.

对于每个 $k=1,2,\ldots,N$,求 $X_k$ 的数位和的最小可能值。AI (CI翻译)

Solve independently for each $k$. That is, for different $k$, the way to determine the integer sequence $X$ that minimizes the digit sum of $X_k$ may be different.

每个 $k$ 独立求解。也就是说,对于不同的 $k$,使 $X_k$ 的数位和最小的整数序列 $X$ 的确定方式可能不同。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1\leq N\leq 20000$
  • $1\leq A_i \leq 10^9-1$
  • $1\leq B_i \leq 10^9-1$
  • All input values are integers.
  • $1\leq N\leq 20000$
  • $1\leq A_i \leq 10^9-1$
  • $1\leq B_i \leq 10^9-1$
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入以以下格式给出:AI (CI翻译)

N
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N

N
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N
AI (CI翻译)

Output

输出格式

AI (CI翻译)

For $k=1,2,\ldots,N$, output the minimum possible digit sum of $X_k$, space-separated.

对于 $k=1,2,\ldots,N$,以空格分隔输出 $X_k$ 的数位和的最小可能值。AI (CI翻译)

样例

Input #1
2
123 444
456 222
Output #1
6 9
The possible integer sequences $X=(X_0,X_1,X_2)$ are the following four: - $X = (0, 123, 1674)$ - $X = (0, 123, 1452)$ - $X = (0, 456, 5004)$ - $X = (0, 456, 4782)$ The minimum possible digit sum of $X_1$ is $6$, which is the digit sum of $123$. The minimum possible digit sum of $X_2$ is $9$, which is the digit sum of $5004$.
Input #2
15
47640 28384 12457 87254 35032 27915 72870 32688 59091 95771 44037 44252 82222 87110 45829
41522 28795 85247 87801 45150 79509 15308 17923 75921 14992 71984 7601 42312 98436 36545
Output #2
14 18 26 19 28 33 28 34 29 27 29 39 35 43 41
题目信息

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