답안 #674655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674655 2022-12-25T16:00:48 Z vjudge1 Kamenčići (COCI21_kamencici) C++17
0 / 70
1 ms 316 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
 
#define F first
#define S second
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define vpi vector<pi>
#define vb vector<bool>
#define vvb vector<vb>
#define pb push_back
#define ppb pop_back
#define read(a) for(auto &x:a) cin >> x;
#define print(a) for(auto x:a) cout << x << " "; cout << "\n";
#define vc vector<char>
#define vvc vector<vc>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#define int long long
#define ld long double
const int INF = 4e18;

void solve(){
    int n, k; cin >> n >> k;
    string s; cin >> s;

    int a = 0, b = 0, l = 0, r = n-1, t = 0;
    while(l <= r){
        if(s[l] == 'P'){
            l++; t = 1-t;
            continue;
        }
        if(s[r] == 'P'){
            r--; t = 1-t;
            continue;
        }

        if(t == 0 && a == k-1){
            cout << "NE\n";
            return;
        }
        if(t == 1 && b == k-1){
            cout << "DA\n";
            return;
        }

        int dl = 0, dr = 0, ix;
        ix = l;
        while(s[ix] == 'C') dl++, ix++;
        ix = r;
        while(s[ix] == 'C') dr++, ix--;

        if(dl > dr){
            l++;
            if(t == 0) a++;
            else b++;
            t = 1-t;
            continue;
        } else {
            r--;
            if(t == 0) a++;
            else b++;
            t = 1-t;
            continue;
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    // #ifndef ONLINE_JUDGE
    //     freopen("in.txt", "r", stdin);
    //     freopen("out.txt", "w", stdout);
    // #endif

    int tt = 1;
    // cin >> tt;
    while(tt--)
        solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 316 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 316 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 316 KB Output isn't correct
3 Halted 0 ms 0 KB -