Submission #499423

# Submission time Handle Problem Language Result Execution time Memory
499423 2021-12-28T11:39:58 Z Haboosh915 Kamenčići (COCI21_kamencici) C++17
30 / 70
1 ms 204 KB
#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 time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 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 0 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 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 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 0 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 204 KB Output is correct
14 Incorrect 1 ms 204 KB Output isn't correct
15 Halted 0 ms 0 KB -