0% found this document useful (0 votes)
13 views

Reconstruction Codeforces

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Reconstruction Codeforces

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

6/9/24, 10:16 PM Problem - F - Codeforces

 |
NguyenDucHien | Logout

HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS HACKS ROOM STANDINGS CUSTOM INVOCATION

Codeforces Global Round 26


F. Reconstruction Contest is running
time limit per test: 2 seconds
02:18:08
memory limit per test: 256 megabytes
input: standard input Contestant
output: standard output

There is a hidden array a1 , a2 , … , an of length n whose elements are integers between


−m and m, inclusive. → Submit?
You are given an array b1 , b2 , … , bn of length n and a string s of length n consisting of the
characters P, S, and ?. Language: Python 3.8.10
Almost always, if you send a solution
on PyPy, it works much faster
For each i from 1 to n inclusive, we must have:
Choose
Choose File No file chosen
file:
If si = P, bi is the sum of a1 through ai .
Be careful: there is 50 points penalty for
If si = S, bi is the sum of ai through an . submission which fails the pretests or
resubmission (except failure on the first test,
Output the number of ways to replace all ? in s with either P or S such that there exists an denial of judgement or similar verdicts).
"Passed pretests" submission verdict doesn't
array a1 , a2 , … , an with elements not exceeding m by absolute value satisfying the guarantee that the solution is absolutely
constraints given by the array b1 , b2 , … , bn and the string s . correct and it will pass system tests.

Since the answer may be large, output it modulo 998 244 353 . Submit

Input
The first line contains a single integer t (1 ≤ t ≤ 103 ) — the number of test cases. → Score table
3
The first line of each test case contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10 , Score
9
2 ≤ m ≤ 10 ) — the length of the hidden array a1 , a2 , … , an and the maximum absolute Problem A 446
value of an element ai . Problem B 668

The second line of each test case contains a string s of length n consisting of characters P, S, Problem C1 668
and ?. Problem C2 1114
Problem D 2227
The third line of each test case contains n integers b1 , b2 , … , bn (|bi | ≤ m ⋅ n).
Problem E 2672
3
The sum of n over all test cases does not exceed 5 ⋅ 10 . Problem F 2672

Output Problem G 3563


For each test case, output a single integer — the number of ways to replace all ? in s with Problem H 4454
1 either P or S that result in the existence of a valid array a1 , a2 , … , an , modulo 998 244 353 .
Successful hack 100

Example Unsuccessful hack -50

input Copy Unsuccessful submission -50

6 Resubmission -50
4 10 * If you solve problem on 00:41 from the first attempt
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701
-178537332
4 7
PPSS
4 2 1 3

https://codeforces.com/contest/1984/problem/F 1/2
6/9/24, 10:16 PM Problem - F - Codeforces
9 20
 ?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396

output Copy

1
0
2
1
14
1
Note
In the first test case, we can see that the following array satisfies all constraints, thus the
answer is 1:

1. P — [1, 3, 4, 2]: sum of 1.


2. S — [1, 3, 4, 2]: sum of 9.
3. P — [1, 3, 4, 2]: sum of 8.
4. P — [1, 3, 4, 2]: sum of 10 .

9
In the second test case, it can be shown that no array a with all |ai | ≤ m = 10 satisfies all
constraints.

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jun/09/2024 22:16:48UTC+7 (j2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

https://codeforces.com/contest/1984/problem/F 2/2

You might also like