CF2170D.Almost Roman
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's define a value of a string, consisting of letters "XVI", as follows:
- the value of 'X' is 10;
- the value of 'V' is 5;
- the value of 'I' is 1 or −1: −1 if the next position contains a letter 'X' or 'V'; 1 otherwise;
- the value of the entire string is the sum of the values of all letters in it.
You are given a string of characters "XVI?" and asked q queries about it.
In the i-th query, three integers are provided:
- cX cV cI — the number of available letters 'X', 'V', and 'I', respectively.
What is the minimum value of the string that can be obtained if all question marks are replaced with the letters 'X', 'V', 'I' so that the number of used letters does not exceed the number of available letters of each type?
我们定义由字母“XVI”组成的字符串的值如下:
- 字母 'X' 的值为 10;
- 字母 'V' 的值为 5;
- 字母 'I' 的值为 1 或 −1:若其后一个位置的字符是 'X' 或 'V',则值为 −1;否则为 1;
- 整个字符串的值等于其中所有字母的值之和。
给定一个由字符 “XVI?” 组成的字符串,并提出 q 个查询。
在第 i 个查询中,给出三个整数:
- cX cV cI —— 分别表示可用的字母 'X'、'V' 和 'I' 的数量。
若将字符串中所有问号 '?' 替换为字母 'X'、'V'、'I',且每种字母的使用数量不超过其可用数量,则所能得到的字符串的最小可能值是多少?
输入格式
The first line contains one integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains two integers n and q (1≤n,q≤3⋅105) — the length of the string and the number of queries, respectively.
The second line contains a string consisting of n characters 'X', 'V', 'I' and/or '?'.
The i-th of the following q lines contains three integers cX,cV, and cI (0≤cX,cV,cI≤n) — the number of available letters 'X', 'V' and 'I' in the i-th query.
Additional constraints on the input:
- the sum of n over all test cases does not exceed 3⋅105;
- the sum of q over all test cases does not exceed 3⋅105;
- cX+cV+cI is greater than or equal to the number of '?' characters in the given string.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 q(1≤n,q≤3⋅105)—— 字符串的长度和查询次数。
第二行包含一个由 n 个字符组成的字符串,每个字符为 'X'、'V'、'I' 或 '?'。
接下来的 q 行中,第 i 行包含三个整数 cX、cV 和 cI(0≤cX,cV,cI≤n)—— 第 i 次查询中可用的字母 'X'、'V' 和 'I' 的数量。
输入的额外约束条件:
- 所有测试用例的 n 之和不超过 3⋅105;
- 所有测试用例的 q 之和不超过 3⋅105;
- 对于每次查询,均有 cX+cV+cI≥ 给定字符串中 '?' 字符的个数。
输出格式
For each query, print a single integer — the minimum value of the string that can be obtained by replacing all question marks with the available letters 'X', 'V', and/or 'I'.
对于每个查询,输出一个整数——通过将所有问号替换为可用的字母 'X'、'V' 和/或 'I' 所能得到的字符串的最小值。
输入输出样例
输入#1
4 3 3 ??? 3 0 0 2 3 1 0 1 2 10 7 ??IV?VXIV? 0 0 4 4 4 0 1 1 2 1 1 3 1 1 4 1 2 1 2 2 0 9 5 ?V????IVV 9 2 4 4 1 5 0 1 4 4 8 1 3 2 7 3 2 I?V 0 1 0 0 0 1
输出#1
30 9 5 25 43 36 27 25 42 53 19 17 19 33 17 9 5
输入解题思路,AI测评打分。不知道怎么写?