CF901E.Cyclic Cipher

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Senor Vorpal Kickass'o invented an innovative method to encrypt integer sequences of length n. To encrypt a sequence, one has to choose a secret sequence , that acts as a key.

Vorpal is very selective, so the key should be such a sequence b__i, that its cyclic shifts are linearly independent, that is, there is no non-zero set of coefficients _x_0, _x_1, ..., x__n - 1, such that for all k at the same time.

After that for a sequence you should build the following cipher:

In other words, you are to compute the quadratic deviation between each cyclic shift of b__i and the sequence a__i. The resulting sequence is the Kickass's cipher. The cipher is in development right now and Vorpal wants to decipher a sequence after it has been encrypted. You are to solve this problem for him. You are given sequences c__i and b__i. You are to find all suitable sequences a__i.

森奥·沃帕尔·基卡索(Senor Vorpal Kickass'o)发明了一种创新方法,用于加密长度为 nn 的整数序列。要加密一个序列,需选择一个作为密钥的秘密序列 。

沃帕尔非常挑剔,因此该密钥序列 bib_i 必须满足:其所有循环移位是线性无关的,即不存在一组不全为零的系数 x0, x1, ..., xn−1x_0,\,x_1,\,...,\,x_{n-1},使得对所有 kk 同时成立
。

随后,对于给定序列 ,应构造如下密文:

换言之,需对 bib_i 的每个循环移位与序列 aia_i 计算二次偏差(即平方差之和)。所得序列即为基卡索密文(Kickass's cipher)。该密文目前尚在开发中,而沃帕尔希望在序列被加密后能将其解密。你需要帮他解决这一问题。现给出密文序列 cic_i 和密钥序列 bib_i,请找出所有满足条件的原序列 aia_i。

输入格式

The first line contains a single integer n ().

The second line contains n integers _b_0, _b_1, ..., b__n - 1 ().

The third line contains n integers _c_0, _c_1, ..., c__n - 1 ().

It is guaranteed that all cyclic shifts of sequence b__i are linearly independent.

第一行包含一个整数 $ n $()。

第二行包含 $ n $ 个整数 $ b_0,,b_1,,\dots,,b_{n-1} $()。

第三行包含 $ n $ 个整数 $ c_0,,c_1,,\dots,,c_{n-1} $()。

保证序列 $ b_i $ 的所有循环移位是线性无关的。

输出格式

In the first line print a single integer k — the number of sequences a__i, such that after encrypting them with key b__i you get the sequence c__i.

After that in each of k next lines print n integers _a_0, _a_1, ..., a__n - 1. Print the sequences in lexicographical order.

Note that k could be equal to 0.

第一行输出一个整数 kk —— 满足“使用密钥 bib_i 对其加密后得到序列 cic_i”的序列 aia_i 的个数。

随后的 kk 行中,每行输出 nn 个整数 a0, a1, …, an−1a_0,\ a_1,\ \ldots,\ a_{n-1}。请按字典序输出这些序列。

注意:kk 可能为 0。

输入输出样例

  • 输入#1

    1
    1
    0

    输出#1

    1
    1
  • 输入#2

    1
    100
    81

    输出#2

    2
    91
    109
  • 输入#3

    3
    1 1 3
    165 185 197

    输出#3

    2
    -6 -9 -1
    8 5 13

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

首页