Submission #717226

#TimeUsernameProblemLanguageResultExecution timeMemory
717226JuanKamenčići (COCI21_kamencici)C++14
70 / 70
103 ms175460 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int, int> #define ff first #define ss second #define all(x) x.begin(), x.end() const int maxn = 355; int dp[maxn][maxn][maxn], v[maxn]; bool solve(int l, int r, int pbs1, int pbs2, int p){ if(dp[l][r][pbs1]!=-1) return dp[l][r][pbs1]; if(pbs1==0 || pbs2==0) return dp[l][r][pbs1] = (pbs2==0); if(p==1){ return dp[l][r][pbs1] = max(solve(l+1, r, pbs1-v[l], pbs2, 2), solve(l, r-1, pbs1-v[r], pbs2, 2)); } else{ return dp[l][r][pbs1] = min(solve(l+1, r, pbs1, pbs2-v[l], 1), solve(l, r-1, pbs1, pbs2-v[r], 1)); } } int main(){ int n, k; cin >> n >> k; for(int i = 0; i < n; i++){ char c; cin >> c; v[i] = (c=='C'); } memset(dp, -1, sizeof dp); if(solve(0, n-1, k, k, 1)) cout << "DA\n"; else cout << "NE\n"; }

Compilation message (stderr)

Main.cpp: In function 'bool solve(int, int, int, int, int)':
Main.cpp:13:47: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   13 |  if(pbs1==0 || pbs2==0) return dp[l][r][pbs1] = (pbs2==0);
      |                                ~~~~~~~~~~~~~~~^~~~~~~~~~~
Main.cpp:16:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   16 |   return dp[l][r][pbs1] = max(solve(l+1, r, pbs1-v[l], pbs2, 2), solve(l, r-1, pbs1-v[r], pbs2, 2));
      |          ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:19:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   19 |   return dp[l][r][pbs1] = min(solve(l+1, r, pbs1, pbs2-v[l], 1), solve(l, r-1, pbs1, pbs2-v[r], 1));
      |          ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...