Submission #1268582

#TimeUsernameProblemLanguageResultExecution timeMemory
1268582ilovewaguriKamenčići (COCI21_kamencici)C++20
70 / 70
84 ms175536 KiB
#include<bits/stdc++.h> using namespace std; #define NAME "KAMENCICI" #define nl '\n' #define allofa(x,sz) x,x+sz+1 #define allof(x) x.begin(),x.end() #define allof1(x) x.begin()+1,x.end() #define mset(x,val) memset(x,val,sizeof(x)) #define couf(x) cout << fixed << setprecision(x) template<class T> T Abs(T &x) {return (x>=0 ? x : -x);}; template<class X,class Y> bool minimize(X &a, Y b){if(a>b) {a=b;return true;}return false;}; template<class X,class Y> bool maximize(X &a, Y b){if(a<b) {a=b;return true;}return false;}; typedef long long ll; const ll mod = (long long)1e9+7; const ll LINF = (long long)1e15; const int INF = (int)1e9; const int MAXN = (int)355; int dp[MAXN][MAXN][MAXN]; //dp[l][r][take]; char a[MAXN]; int pref[MAXN]; int redP; int n,k; void ccps() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); if(fopen(NAME".inp","r")) { freopen(NAME".inp","r",stdin); freopen(NAME".out","w",stdout); } } bool sol(int l, int r, int take) { if(dp[l][r][take]!=-1) return dp[l][r][take]; int notTake = pref[r]-pref[l-1]; int ot = redP - notTake - take; if(take>=k) dp[l][r][take]=false; else if(ot>=k) dp[l][r][take]=true; else { if(!sol(l+1,r,ot) or !sol(l,r-1,ot)) dp[l][r][take]=true; else dp[l][r][take]=false; } return dp[l][r][take]; } signed main() { ccps(); cin >> n >> k; for (int i = 1; i<=n; i++) { cin >> a[i]; } for (int i = 1; i<=n; i++) { pref[i]=pref[i-1]+(a[i]=='C'); } redP=pref[n]; mset(dp,-1); cout << (sol(1,n,0) ? "DA" : "NE"); }

Compilation message (stderr)

Main.cpp: In function 'void ccps()':
Main.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen(NAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...