Problem Statement ErnKor is willing to do anything for Julen, even swimming through…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
Problem Statement
ErnKor is willing to do anything for Julen, even swimming through crocodile-infested swamps. To test this love, ErnKor has to swim across a river that is 1 meter wide and ( n ) meters long.
The river is extremely cold. Therefore, throughout the entire swim from 0 to ( n+1 ), ErnKor can swim in the water for no more than ( k ) meters. To make the test more challenging, the river contains not only crocodiles but also logs on which ErnKor can jump. The test is as follows:
- Initially, ErnKor is on the left bank and needs to reach the right bank. The banks are located at 0 and ( n+1 ) meters respectively.
- The river can be represented as ( n ) segments, each with a length of 1 meter.
- Each segment contains either a log 'L', a crocodile 'C', or just water 'W'.
ErnKor's movements are as follows:
- If he is on the surface (i.e., on the bank or on a log), he can jump forward for no more than ( m ) (1 ≤ ( m ) ≤ 10) meters (he can jump to the bank, a log, or into the water).
- If he is in the water, he can only swim to the next river segment (or to the bank if he is at the ( n )-th meter).
- ErnKor cannot land in a segment with a crocodile in any way.
Determine if ErnKor can reach the right bank.
Input
- The first line contains a single integer ( t ) (1 ≤ ( t ) ≤ 10^4) — the number of test cases.
- For each test case:
- The first line contains three integers ( n ), ( m ), ( k ) (0 ≤ ( k ) ≤ 2⋅10^5, 1 ≤ ( n ) ≤ 2⋅10^5, 1 ≤ ( m ) ≤ 10) — the length of the river, the maximum distance ErnKor can jump, and the maximum meters ErnKor can swim without freezing.
- The second line contains a string ( a ) of length ( n ). ( a_i ) denotes the object located at the ( i )-th meter (( a_i \in { 'W', 'C', 'L' } )).
It is guaranteed that the sum of ( n ) over all test cases does not exceed 2⋅10^5.
Output
For each test case, output "YES" if ErnKor can pass the test, and "NO" otherwise. The answer can be in any case (e.g., "yEs", "yes", "Yes", and "YES" are all valid).
Example
Input
code6 6 2 0 LWLLLW 6 1 1 LWLLLL 6 1 1 LWLLWL 6 2 15 LWLLCC 6 10 0 CCCCCC 6 6 1 WCCCCWOutput
codeYES YES NO NO YES YESNote
Example Explanation:
-
First example:
- Path: 0→1 (log), 1→3 (log), 3→5 (log), 5→7 (bank).
Assistant
cpp#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; const int INF = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; string s; cin >> s; vector<int> dp(n + 2, INF); dp[0] = 0; bool ans = false; for (int i = 0; i <= n; i++) { for (int j = 1; j <= m && i + j <= n + 1; j++) { if (s[i] == 'C') break; if (dp[i] != INF) { if (i + j == n + 1) { ans = true; } else if (s[i + j] != 'C') { dp[i + j] = min(dp[i + j], dp[i] + (s[i + j] == 'W')); } } } if (ans || dp[i] > k) break; } cout << (ans && dp[n + 1] <= k ? "YES\n" : "NO\n"); } return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.