#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ss second
#define ff first
int main() {
int n , k ; cin >> n >> k ;
string s ; cin >> s ;
pair <int , char> a[n+4] ;
int idx = 0 ;
int kf = 0 , ks = 0 ;
int p = 0 , c = 0 ;
for (int i = 0 ; i < n ; i++ ) {
if ( s[i] == 'P' ) {
if ( c != 0 ) {
idx ++ ; a[idx].ff = c ; a[idx].ss = 'C' ;
c = 0 ;
}
p ++ ;
}
else {
if ( p != 0 ) {
idx ++ ; a[idx].ff = p ; a[idx].ss = 'P' ;
p = 0 ;
}
c ++ ;
}
}
if ( p > 0 ) {
idx ++ ; a[idx].ff = p ; a[idx].ss = 'P' ;
}
if ( c > 0 ) {
idx ++ ; a[idx].ff = c ; a[idx].ss = 'C' ;
}
int turn = 1 ;
int l = 1 , r = idx ;
for ( int i = 1; i <= n ; i ++ ) {
if ( turn == 1 ) {
if ( a[l].ss != a[r].ss ){
if (a[l].ss == 'P' ) a[l].ff--;
else {a[r].ff-- ; }
}
else if ( a[l].ss == 'C' && a[r].ss == 'C' ) {
if ( a[l].ff == a[r].ff-1 ) {
a[r].ff -- ; kf ++ ;
}
else if ( a[r].ff == a[l].ff-1 ) {
a[l].ff -- ; kf ++ ;
}
else {
if ( a[l].ff < a[r].ff ) {
a[l].ff -- ; kf ++ ;
}
else {
a[r].ff -- ; kf ++ ;
}
}
}
else {
int pl = a[l].ff / 2 ;
if ( a[l].ff % 2 ) pl ++ ;
int pr = a[r].ff / 2 ;
if ( a[r].ff % 2 ) pr ++ ;
if ( pl > pr ) {
a[l].ff -- ;
}
else {
a[r].ff -- ;
}
}
turn ++ ;
}
if ( kf >= k ) break ;
if ( a[l].ff == 0 ) l ++ ;
if ( a[r].ff == 0 ) r-- ;
if ( turn == 2 ) {
if ( a[l].ss != a[r].ss ){
if (a[l].ss == 'P' ) a[l].ff--;
else a[r].ff-- ;
}
else if ( a[l].ss == 'C' && a[r].ss == 'C' ) {
if ( a[l].ff == a[r].ff-1 ) {
a[r].ff -- ; ks ++ ;
}
else if ( a[r].ff == a[l].ff-1 ) {
a[l].ff -- ; ks ++ ;
}
else {
if ( a[l].ff < a[r].ff ) {
a[l].ff -- ; ks ++ ;
}
else {
a[r].ff -- ; ks ++ ;
}
}
}
else {
int pl = a[l].ff / 2 ;
if ( a[l].ff % 2 ) pl ++ ;
int pr = a[r].ff / 2 ;
if ( a[r].ff % 2 ) pr ++ ;
if ( pl > pr ) {
a[l].ff -- ;
}
else {
a[r].ff -- ;
}
}
turn -- ;
}
if ( ks >= k ) break ;
if ( a[l].ff == 0 ) l ++ ;
if ( a[r].ff == 0 ) r -- ;
}
if ( ks >= k ) cout << "DA" ;
else cout << "NE" ;
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
288 KB |
Output is correct |
14 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |