| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1345781 | msb.83 | Kamenčići (COCI21_kamencici) | C++20 | 1 ms | 344 KiB |
//Rahman ve Rahim olan Allah'ın adıyla
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mid ((st+end)/2)
#define hes (pre[n]-k2-(pre[r+1]-pre[l]))
#define fi first
#define se second
const int INF=1e15+5;
const int E16=1e6;
const int ONE=1;
const int TWO=2;
const int ZERO=0;
const int MOD=1e9+7;//(x+MOD)%MOD
//el.erase(unique(el.begin(),el.end()),el.end());
int n,k;vector<vector<vector<int>>>dp;vector<int>pre;string s;
inline bool func(int l,int r,int k2){
if(dp[l][r][k2]!=-1){return dp[l][r][k2];}cerr<<l<<" "<<r<<" "<<k2<<"\n";
if(k2>=k){return true;}if(hes>=k){return false;}
if((l+(n-r))%2){
dp[l][r][k2]=func(l+1,r,k2)||func(l,r-1,k2);
return dp[l][r][k2];
}else{
bool b1,b2;
if(s[l]=='C'){
b1=func(l+1,r,k2+1);
}else{
b1=func(l+1,r,k2);
}
if(s[r]=='C'){
b2=func(l,r-1,k2+1);
}else{
b2=func(l,r-1,k2);
}
dp[l][r][k2]=b1&&b2;
return dp[l][r][k2];
}
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
cin>>n>>k>>s;pre.resize(n+1);pre[0]=0;dp.resize(n,vector<vector<int>>(n,vector<int>(k+1,-1)));
for(int i=1;i<=n;i++){pre[i]=pre[i-1];if(s[i-1]=='C'){pre[i]++;}}
if(func(0,n-1,0)){cout<<"DA\n";}else{cout<<"NE\n";}
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
