Submission #1200978

#TimeUsernameProblemLanguageResultExecution timeMemory
1200978MighilonKamenčići (COCI21_kamencici)C++20
10 / 70
1100 ms86692 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "../Library/debug.h" #else #define dbg(x...) #endif typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) for (int i = 0; i < (a); ++i) #define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i) #define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i) #define trav(a, x) for (auto& a : x) #define f first #define s second #define pb push_back #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() const char nl = '\n'; const int INF = 1e9; const int MOD = 1e9 + 7; int dp[350][350][180]; int n,k; string s; vi p; int f(int l, int r, int i, int j){ // if(~dp[l][r][i]) // return dp[l][r][i]; int c=p[n-1]-p[r]+(l?p[l-1]:0)-i; /* if j==0 c=k return 1 i=k return 0 if j==1 c=k return 0 i=k return 1 j changes */ if(c==k){ return j; } else if(i==k){ return j^1; } assert(l<=r); int x=0; if(s[l]=='P'){ x|=f(l+1,r,i,j^1); } else{ x|=f(l+1,r,i+(j^1),j^1); } if(s[r]=='P'){ x|=f(l,r-1,i,j^1); } else{ x|=f(l,r-1,i+(j^1),j^1); } dp[l][r][i]=x; return x^1; } void solve(){ cin>>n>>k; cin>>s; memset(dp,-1, sizeof dp); p.resize(n); p[0]=s[0]=='C'; FOR(i,1,sz(s)){ p[i]=(s[i]=='C')+p[i-1]; } if(!f(0,n-1,0,0)) cout<<"DA\n"; else cout<<"NE\n"; } int32_t main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int TC = 1; // cin >> TC; while(TC--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...