CF1225G.To Make 1

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There are nn positive integers written on the blackboard. Also, a positive number k≥2k \geq 2 is chosen, and none of the numbers on the blackboard are divisible by kk. In one operation, you can choose any two integers xx and yy, erase them and write one extra number f(x+y)f(x + y), where f(x)f(x) is equal to xx if xx is not divisible by kk, otherwise f(x)=f(x/k)f(x) = f(x / k).

In the end, there will be a single number of the blackboard. Is it possible to make the final number equal to 11? If so, restore any sequence of operations to do so.

黑板上写着 nn 个正整数。此外,选定一个正整数 k≥2k \geq 2,且黑板上的所有数均不被 kk 整除。每次操作中,你可以任选两个整数 xx 和 yy,将它们擦除,并额外写下数字 f(x+y)f(x + y),其中函数 f(x)f(x) 定义如下:若 xx 不被 kk 整除,则 f(x)=xf(x) = x;否则(即 xx 被 kk 整除),f(x)=f(x/k)f(x) = f(x / k)。

最终,黑板上将仅剩一个数。能否通过若干次操作使得该最终数恰好等于 11?若可以,请还原出任意一种可行的操作序列。

输入格式

The first line contains two integers nn and kk — the initial number of integers on the blackboard, and the chosen number (2≤n≤162 \leq n \leq 16, 2≤k≤20002 \leq k \leq 2000).

The second line contains nn positive integers a1,…,ana_1, \ldots, a_n initially written on the blackboard. It is guaranteed that none of the numbers aia_i is divisible by kk, and the sum of all aia_i does not exceed 20002000.

第一行包含两个整数 nn 和 kk —— 黑板上初始的整数个数,以及选定的数(2≤n≤162 \leq n \leq 16,2≤k≤20002 \leq k \leq 2000)。

第二行包含 nn 个正整数 a1,…,ana_1, \ldots, a_n,它们初始写在黑板上。保证每个数 aia_i 均不能被 kk 整除,且所有 aia_i 的总和不超过 20002000。

输出格式

If it is impossible to obtain 11 as the final number, print "NO" in the only line.

Otherwise, print "YES" on the first line, followed by n−1n - 1 lines describing operations. The ii-th of these lines has to contain two integers xix_i and yiy_i to be erased and replaced with f(xi+yi)f(x_i + y_i) on the ii-th operation. If there are several suitable ways, output any of them.

如果无法得到最终数字 11,则在唯一一行中输出 "NO"。

否则,在第一行输出 "YES",随后输出 n−1n - 1 行,每行描述一次操作。其中第 ii 行需包含两个整数 xix_i 和 yiy_i,表示在第 ii 次操作中将它们擦除并替换为 f(xi+yi)f(x_i + y_i)。若存在多种可行方案,输出任意一种即可。

输入输出样例

  • 输入#1

    2 2
    1 1

    输出#1

    YES
    1 1
  • 输入#2

    4 3
    7 8 13 23

    输出#2

    YES
    23 13
    8 7
    5 4
  • 输入#3

    3 4
    1 2 3

    输出#3

    NO

说明/提示

In the second sample case:

  • f(8+7)=f(15)=f(5)=5f(8 + 7) = f(15) = f(5) = 5;
  • f(23+13)=f(36)=f(12)=f(4)=4f(23 + 13) = f(36) = f(12) = f(4) = 4;
  • f(5+4)=f(9)=f(3)=f(1)=1f(5 + 4) = f(9) = f(3) = f(1) = 1.

在第二个样例中:

  • f(8+7)=f(15)=f(5)=5f(8 + 7) = f(15) = f(5) = 5;
  • f(23+13)=f(36)=f(12)=f(4)=4f(23 + 13) = f(36) = f(12) = f(4) = 4;
  • f(5+4)=f(9)=f(3)=f(1)=1f(5 + 4) = f(9) = f(3) = f(1) = 1。

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

首页