Submission #499423

#TimeUsernameProblemLanguageResultExecution timeMemory
499423Haboosh915Kamenčići (COCI21_kamencici)C++17
30 / 70
1 ms204 KiB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ll long long
#define ss second
#define ff first


int main() {

    ll n , k ; cin >> n >> k ;
    string s ; cin >> s ;

    pair <ll , char> a[n+4] ;
    ll idx = 0 ;
    ll kf = 0 , ks = 0 ;

    ll 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' ;
    }

    ll turn = 1 ;
    ll 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 {
                ll pl = a[l].ff / 2 ;
                if ( a[l].ff % 2 ) pl ++ ;
                ll 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 {
                ll pl = a[l].ff / 2 ;
                if ( a[l].ff % 2 ) pl ++ ;
                ll 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...