luogu#P7928. [COCI 2021/2022 #1] Kamenčići

[COCI 2021/2022 #1] Kamenčići

Problem Description

Alice and Bob are playing a game again.

In front of them, there are nn stones in a row. Each stone is either red or blue.

Alice moves first. On each turn, a player chooses one end and takes one stone from that end. Whoever takes kk red stones first loses.

Assuming both Alice and Bob play optimally, determine who will win in the end.

Input Format

The first line contains two integers n,kn, k.

The next line contains a string of length nn, consisting only of C and P. C represents a red stone, and P represents a blue stone.

Output Format

If Alice is guaranteed to win, output DA; otherwise, output NE.

4 1
CCCP
DA
8 2
PCPPCCCC

DA
9 1
PPCPPCPPC
NE

Hint

Constraints

For all testdata, 1k<n3501 \le k < n \le 350, and red stones appear at least 2k12k-1 times.

Subtask Special Constraint Score
11 n20n \le 20 1010
22 n50n \le 50 2020
33 No special constraints. 4040

Notes

The total score of this problem is 7070 points.

This problem is translated from Croatian Open Competition in Informatics 2021/2022 Contest #1 T2 Kamenčići.

Translated by ChatGPT 5