CF101E.Candies and Stones

省选/NOI-

通过率:0%

时间限制:7.50s

内存限制:45MB

AC君温馨提醒

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

题目描述

Little Gerald and his coach Mike play an interesting game. At the beginning of the game there is a pile consisting of n candies and a pile consisting of m stones. Gerald and Mike move in turns, Mike goes first. During his move Mike checks how many candies and stones Gerald has eaten. Let Gerald eat a candies and b stones. Then Mike awards Gerald f(a, b) prize points. Gerald during his move either eats a candy from the pile of candies or a stone from the pile of stones. As Mike sees that Gerald has eaten everything apart one candy and one stone, he awards points for the last time and the game ends. Gerald is not allowed to eat all the candies, and he is not allowed to eat all the stones too. Tell Gerald how to play to get the largest possible number of points: it is required to find one of the possible optimal playing strategies for Gerald.

小杰拉尔德和他的教练迈克玩一个有趣的游戏。游戏开始时,有一堆包含 nn 颗糖果的糖果堆和一堆包含 mm 块石头的石头堆。杰拉尔德与迈克轮流进行操作,迈克先手。在迈克的操作中,他检查杰拉尔德迄今已吃掉的糖果数和石头数:设杰拉尔德已吃掉 aa 颗糖果和 bb 块石头,则迈克授予杰拉尔德 f(a, b)f(a,\,b) 分奖励积分。在杰拉尔德的操作中,他只能从糖果堆中吃掉一颗糖果,或从石头堆中吃掉一块石头。当迈克发现杰拉尔德已将糖果堆和石头堆分别仅剩一颗糖果和一块石头时,他最后一次授予积分,游戏随即结束。杰拉尔德不允许吃掉全部糖果,也不允许吃掉全部石头。请告诉杰拉尔德如何操作才能获得尽可能多的积分:即要求找出杰拉尔德的一种可能的最优策略。

输入格式

The first line contains three integers n, m, p (1 ≤ n, m ≤ 20000, 1 ≤ p ≤ 109). The second line contains n integers _x_0, _x_1, ..., x__n - 1 (0 ≤ x__i ≤ 20000). The third line contains m integers _y_0, _y_1, ..., y__m - 1 (0 ≤ y__i ≤ 20000). The value of f(a, b) is calculated as a remainder of the division of the sum x__a + y__b by number p.

第一行包含三个整数 nn、mm、pp(1≤n,m≤200001 \leq n, m \leq 20000,1≤p≤1091 \leq p \leq 10^9)。
第二行包含 nn 个整数 x0,x1,…,xn−1x_0, x_1, \dots, x_{n-1}(0≤xi≤200000 \leq x_i \leq 20000)。
第三行包含 mm 个整数 y0,y1,…,ym−1y_0, y_1, \dots, y_{m-1}(0≤yi≤200000 \leq y_i \leq 20000)。
函数 f(a,b)f(a, b) 的值定义为和 xa+ybx_a + y_b 除以 pp 所得的余数。

输出格式

Print on the first line the only number: the maximal number of points Gerald can earn. Print on the second line a sting consisting of n + m - 2 characters, each of which is either a "C" or "S", the i-th character should be "C" if Gerald's i-th move should be eating a candy and "S" if he should eat a stone.

第一行输出唯一的一个数字:杰拉尔德能够获得的最大分数。
第二行输出一个由 n+m−2n + m - 2 个字符组成的字符串,每个字符为 "C" 或 "S";其中第 ii 个字符为 "C" 表示杰拉尔德的第 ii 步操作应为吃一颗糖果,为 "S" 则表示应吃一颗石头。

输入输出样例

  • 输入#1

    2 2 10
    0 0
    0 1

    输出#1

    2
    SC
  • 输入#2

    3 3 10
    0 2 0
    0 0 2

    输出#2

    10
    CSSC
  • 输入#3

    3 3 2
    0 1 1
    1 1 0

    输出#3

    4
    SCSC

说明/提示

In the first test if Gerald's first move is eating a stone, he will receive a point for it and if he eats a candy, he will get zero pints. In any way Gerald will get 0 points before his first move, and 1 after his second one. This, the maximum number of points Gerald can get equals to 2, and for that he should first eat a stone, then a candy.

在第一次测试中,如果杰拉尔德的第一步是吃一颗石头,他将因此获得 1 分;而如果他第一步吃一颗糖果,则得分为 0。无论哪种情况,杰拉尔德在第一步之前得分为 0,第二步之后得分为 1。因此,杰拉尔德能获得的最高得分为 2,为此他应首先吃一颗石头,然后吃一颗糖果。

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

首页