답안 #499411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499411 2021-12-28T11:23:45 Z Haboosh915 Kamenčići (COCI21_kamencici) C++17
0 / 70
0 ms 296 KB
#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 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 296 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 296 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 296 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -