AT_arc222_d.Shift and Add

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

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

You are given positive integer sequences A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) and B=(B1,B2,…,BN)B=(B_1,B_2,\ldots,B_N).

Using AA and BB, define an integer sequence X=(X0,X1,X2,…,XN)X=(X_0,X_1,X_2,\ldots,X_N) as follows:

  • Set X0=0X_0 = 0.
  • For each i=1,2,…,Ni=1,2,\ldots,N, choose one of Xi=10Xi−1+AiX_i = 10X_{i-1} + A_i and Xi=10Xi−1+BiX_i = 10X_{i-1} + B_i to determine XiX_i.

For each k=1,2,…,Nk=1,2,\ldots,N, find the minimum possible digit sum of XkX_k.

Solve independently for each kk. That is, for different kk, the way to determine the integer sequence XX that minimizes the digit sum of XkX_k may be different.

定义一个非负整数 nn 的数位和为 nn 在十进制表示下各位数字之和。例如,20262026 的数位和为 2+0+2+6=102+0+2+6=10。

给定两个正整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) 和 B=(B1,B2,…,BN)B=(B_1,B_2,\ldots,B_N)。

利用 AA 和 BB,定义一个整数序列 X=(X0,X1,X2,…,XN)X=(X_0,X_1,X_2,\ldots,X_N),方式如下:

  • 令 X0=0X_0 = 0;
  • 对每个 i=1,2,…,Ni=1,2,\ldots,N,从 Xi=10Xi−1+AiX_i = 10X_{i-1} + A_i 与 Xi=10Xi−1+BiX_i = 10X_{i-1} + B_i 中任选其一来确定 XiX_i。

对每个 k=1,2,…,Nk=1,2,\ldots,N,求 XkX_k 的最小可能数位和。

对每个 kk 独立求解。即:对不同的 kk,使 XkX_k 的数位和最小的序列 XX 的构造方式可以不同。

输入格式

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

NN
A1A_1 A2A_2 …\ldots ANA_N
B1B_1 B2B_2 …\ldots BNB_N

输入从标准输入以如下格式给出:

NN
A1A_1 A2A_2 …\ldots ANA_N
B1B_1 B2B_2 …\ldots BNB_N

输出格式

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

对于 k=1,2,…,Nk=1,2,\ldots,N,输出 XkX_k 的最小可能各位数字之和,以空格分隔。

输入输出样例

  • 输入#1

    2
    123 444
    456 222

    输出#1

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

    输出#2

    14 18 26 19 28 33 28 34 29 27 29 39 35 43 41

说明/提示

Sample 1 Explanation:
The possible integer sequences X=(X0,X1,X2)X=(X_0,X_1,X_2) are the following four:

  • X=(0,123,1674)X = (0, 123, 1674)
  • X=(0,123,1452)X = (0, 123, 1452)
  • X=(0,456,5004)X = (0, 456, 5004)
  • X=(0,456,4782)X = (0, 456, 4782)

The minimum possible digit sum of X1X_1 is 66, which is the digit sum of 123123.

The minimum possible digit sum of X2X_2 is 99, which is the digit sum of 50045004.

Constraints

  • 1≤N≤200001\leq N\leq 20000
  • 1≤Ai≤109−11\leq A_i \leq 10^9-1
  • 1≤Bi≤109−11\leq B_i \leq 10^9-1
  • All input values are integers.

样例 1 解释:
可能的整数序列 X=(X0,X1,X2)X=(X_0,X_1,X_2) 共有以下四种:

  • X=(0,123,1674)X = (0, 123, 1674)
  • X=(0,123,1452)X = (0, 123, 1452)
  • X=(0,456,5004)X = (0, 456, 5004)
  • X=(0,456,4782)X = (0, 456, 4782)

X1X_1 的最小可能各位数字之和为 66,即 123123 的各位数字之和。

X2X_2 的最小可能各位数字之和为 99,即 50045004 的各位数字之和。

约束条件

  • 1≤N≤200001\leq N\leq 20000
  • 1≤Ai≤109−11\leq A_i \leq 10^9-1
  • 1≤Bi≤109−11\leq B_i \leq 10^9-1
  • 所有输入值均为整数。

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

首页