CF1358F.Tasty Cookie

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Oh, no!

The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem.

You are given two arrays AA and BB of size nn. You can do operations of two types with array AA:

  • Reverse array AA. That is the array [A1, A2, …, An][A_1,\ A_2,\ \ldots,\ A_n] transformes into [An, An−1, …, A1][A_n,\ A_{n-1},\ \ldots,\ A_1].
  • Replace AA with an array of its prefix sums. That is, the array [A1, A2, …, An][A_1,\ A_2,\ \ldots,\ A_n] goes to [A1, (A1+A2), …, (A1+A2+…+An)][A_1,\ (A_1+A_2),\ \ldots,\ (A_1+A_2+\ldots+A_n)].

You need to understand if you can get an array BB from the array AA. If it is possible, you will have to restore the order of these operations by minimizing the number of operations of the second type. Fortunately, the coronavirus is good today, so he has allowed you not to restore actions if the minimum number of second type operations is more than 2⋅1052\cdot 10^5. But coronavirus resents you, so if you restore the answer, the total number of operations should not exceed 5⋅1055\cdot 10^5.

Solve this problem and get the cookie, or the coronavirus will extend the quarantine for five years and make the whole economy collapse!

哦,不!

你感染了新冠病毒,现在正坐在一间黑暗的地窖里,双腿被绑住(但双手可以活动)。你面前有一块美味的饼干、一台笔记本电脑,以及你理想中的开发环境已经打开。新冠病毒怂恿你解决下面这个问题。

给定两个长度为 nn 的数组 AA 和 BB。你可以对数组 AA 执行以下两种操作:

  • 反转数组 AA:即把数组 [A1, A2, …, An][A_1,\ A_2,\ \ldots,\ A_n] 变为 [An, An−1, …, A1][A_n,\ A_{n-1},\ \ldots,\ A_1]。
  • 将 AA 替换为其前缀和数组:即把数组 [A1, A2, …, An][A_1,\ A_2,\ \ldots,\ A_n] 变为 [A1, (A1+A2), …, (A1+A2+…+An)][A_1,\ (A_1+A_2),\ \ldots,\ (A_1+A_2+\ldots+A_n)]。

你需要判断:能否通过对 AA 执行若干次上述操作得到数组 BB?若可以,还需还原出操作序列,并最小化第二种操作(前缀和操作)的次数。幸运的是,今天新冠病毒心情不错,因此允许你不必还原操作序列,只要最小的第二种操作次数超过 2⋅1052\cdot 10^5 即可。但新冠病毒对你心存怨恨,因此——一旦你选择还原答案,则总操作次数不得超过 5⋅1055\cdot 10^5。

快解决这个问题,赢得那块饼干!否则,新冠病毒将把你的隔离期延长五年,并导致整个经济崩溃!

输入格式

The first line contains a single integer nn (1≤n≤2⋅1051\le n \le 2\cdot 10^5).

The second line contains nn integers A1,A2,…,AnA_1, A_2, \ldots, A_n (1≤Ai≤10121 \le A_i \le 10 ^ {12}).

The third line contains nn integers B1,B2,…,BnB_1, B_2, \ldots, B_n (1≤Bi≤10121 \le B_i \le 10 ^ {12}).

第一行包含一个整数 nn(1≤n≤2⋅1051\le n \le 2\cdot 10^5)。

第二行包含 nn 个整数 A1,A2,…,AnA_1, A_2, \ldots, A_n(1≤Ai≤10121 \le A_i \le 10 ^ {12})。

第三行包含 nn 个整数 B1,B2,…,BnB_1, B_2, \ldots, B_n(1≤Bi≤10121 \le B_i \le 10 ^ {12})。

输出格式

If you cannot get BB from the AA array, print "IMPOSSIBLE" (without quotes) on a single line.

If the minimum number of operations of the second type exceeds 2⋅1052\cdot 10^5, print "BIG" (without quotes). In the second line print the number of operations of the second type, that needs to be applied to get array BB from AA.

Otherwise, in the first line print "SMALL" (without quotes). In the second line print the total number of operations of the first and second types m≤5⋅105m \le 5\cdot 10^5 (it is guaranteed that in this case there is such a sequence of actions). In the third line print a line of length mm, consisting of characters 'R"and 'P' (without quotes).

The ii-th character should be 'R', if the ii-th action is of the first type, and should be 'P', otherwise.

If there are several such sequences, you can print any of them.

You can print each character in the uppercase or in the lowercase.

如果无法通过数组 AA 得到 BB,则在单独一行中输出 "IMPOSSIBLE"(不带引号)。

如果第二种操作的最小次数超过 2⋅1052\cdot 10^5,则输出 "BIG"(不带引号)。第二行输出从 AA 得到数组 BB 所需的第二种操作的次数。

否则,第一行输出 "SMALL"(不带引号);第二行输出第一种与第二种操作的总次数 m≤5⋅105m \le 5\cdot 10^5(题目保证此时存在满足条件的操作序列);第三行输出一个长度为 mm 的字符串,仅由字符 'R' 和 'P'(不带引号)组成。

其中第 ii 个字符为 'R' 表示第 ii 个操作属于第一种类型,为 'P' 表示属于第二种类型。

若存在多个满足条件的操作序列,输出任意一个即可。

每个字符可使用大写或小写形式。

输入输出样例

  • 输入#1

    2
    5 7
    5 7

    输出#1

    SMALL
    0
  • 输入#2

    2
    1 1
    300000 1

    输出#2

    BIG
    299999
  • 输入#3

    2
    10 1
    13 14

    输出#3

    SMALL
    6
    RPPPRP
  • 输入#4

    3
    1 2 1
    2 1 2

    输出#4

    IMPOSSIBLE

说明/提示

In the first example, the arrays AA and BB already equal, so the number of required operations =0=0.

In the second example, we need to replace AA with the prefix sums 299999299999 times and then reverse the array. Since 299999>2⋅105299999 \gt 2\cdot 10^5, there is no need to restore the answer.

In the fourth example, you cannot get BB from the AA.

在第一个例子中,数组 AA 和 BB 已经相等,因此所需操作次数为 00。

在第二个例子中,我们需要对 AA 进行 299999299999 次前缀和替换,然后反转数组。由于 299999>2⋅105299999 \gt 2\cdot 10^5,无需还原答案。

在第四个例子中,无法从 AA 得到 BB。

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

首页