Submission #521862

#TimeUsernameProblemLanguageResultExecution timeMemory
521862BadPenaltyKamenčići (COCI21_kamencici)C++14
10 / 70
1 ms972 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pb push_back #define endl '\n' #define all(x) x.begin(),x.end() #define yes cout<<"Yes"<<endl #define no cout<<"No"<<endl const int N = 410,mod = 1e9+7; int dp[N][N]; int n,k; string s; void solve(int l = 0,int r = n-1,int k1 = 0,int k2 = 0,int i = 1) { int &res = dp[l][r]; if(res!=-1) return; if(k2>=k) res = 1; else if(k1>=k) res = 0; else { if(i == 1) { if(s[l]=='C') solve(l+1,r,k1+1,k2,i+1); else solve(l+1,r,k1,k2,i+1); if(s[r]=='C') solve(l,r-1,k1+1,k2,i+1); else solve(l,r-1,k1,k2,i+1); } else { if(s[l]=='C') solve(l+1,r,k1,k2+1,i-1); else solve(l+1,r,k1,k2,i-1); if(s[r]=='C') solve(l,r-1,k1,k2+1,i-1); else solve(l,r-1,k1,k2,i-1); } if(i==2) { if(dp[l+1][r]==1&&dp[l][r-1]==1) res = 1; else res = 0; } else { if(dp[l+1][r]==1||dp[l][r-1]==1) res = 1; else res = 0; } } //cout<<l<<' '<<r<<' '<<res<<' '<<i<<endl; return; } int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>n>>k>>s; for(int i = 0;i<N;i++)for(int j = 0;j<N;j++) dp[i][j] = -1; solve(); if(dp[0][n-1]) cout<<"DA"<<endl; else cout<<"NE"<<endl; return 0; } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...