This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll _i=0;
#define ffn(x) _i=x
#define llll pair<ll , ll>
#define stitr set<llll>::iterator
#define fora(y,x) for(ll y=_i;x>y;y++)
#define pb push_back
#define pf push_front
#define debu cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e13 + 7;
const ll ous=1e6 + 5;
const ll dx[4] = {1 , -1 , 0 , 0} , dy[4] = {0,0,-1,1};
void solve(){
ll n , k;cin >> n >> k;
string h;cin >> h;
ll turn = 0;
ll l = 0 , r = n-1;
ll play[2];
play[0] = play[1] = 0;
ll dl[n] , dr[n];
memset(dl , 0 , sizeof(dl));
memset(dr , 0 , sizeof(dr));
dl[0] = limit;
dr[n-1] = limit;
for(ll i = 0;n>i;i++){
if(h[i] == 'P'){
dl[i] = 0;
}
else if(i != 0){
dl[i] = dl[i-1]+1;
}
}
for(ll i = n-1;0<=i;i--){
if(h[i] == 'P'){
dr[i] = 0;
}
else if(i != n-1){
dr[i] = dr[i+1] + 1;
}
}
for(ll i = 0;n>i;i++)
while(r >= l){
if(play[1] >= k){
cout << "DA\n";
return;
}
else if(play[0] >= k){
cout << "NE\n";
return;
}
if(h[r] == 'C' && h[l] == 'C'){
if(play[turn%2] >= play[(turn+1)%2]){
play[turn%2]++;
if(dr[r] > dl[l]){
l++;
}
else{
r--;
}
}
else{
play[turn%2]++;
if(dr[r] > dl[l]){
r--;
}
else{
l++;
}
}
}
else{
if(h[l] == 'P'){
l++;
}
else{
r--;
}
}
turn++;
}
return;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
ll t=1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |