답안 #887810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887810 2023-12-15T09:03:23 Z Mr_Ph Kamenčići (COCI21_kamencici) C++17
0 / 70
114 ms 524288 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<x, null_type,
ll mod=(ll)1e9+7;
ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
int dp[352][352][350][2];
vi arr;
int prf[350];
string s;
int k;
    int n;
int ans(int l,int r,int red,int turn)
{
    int red1=prf[n-1]-prf[r];
    red1+=(l?prf[l-1]:0);
    red1-=red;
    if((turn&&red==k)||(!turn&&red1==k))
        return turn;
    if(dp[l][r][red][turn]!=-1)return dp[l][r][red][turn];
    int e=0;
    if(turn)
    {
        e|=ans(l+1,r,red,turn^1);
        e|=ans(l,r-1,red,turn^1);
    }
    else
    {
        e=1;
        e&=ans(l+1,r,red+(s[l]=='C'),turn^1);
        e&=ans(l,r-1,red+(s[r]=='C'),turn^1);
    }
    return dp[l][r][red][turn]=e;
}
void preprocess() {}
void solve()
{
    memset(dp,-1,sizeof dp);
    cin>>n>>k;
    cin>>s;
    prf[0]=s[0]=='C';
    for(int i=1;i<n;i++)
        prf[i]=prf[i-1]+(s[i]=='C');
    if(ans(0,n-1,0,0)!=0)cout<<"NE"<<endl;
    else cout<<"DA"<<endl;
}
signed main()
{
    // freopen("meta_game_input.txt","r",stdin);
    // freopen("otput.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    preprocess();
    int t=1,st;
    //cin>>t;
    while(t--)
        solve();
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:66:13: warning: unused variable 'st' [-Wunused-variable]
   66 |     int t=1,st;
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 114 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 114 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 114 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -