Submission #656220

#TimeUsernameProblemLanguageResultExecution timeMemory
656220Hydroxic_AcidKamenčići (COCI21_kamencici)C++17
70 / 70
81 ms175460 KiB
#include <iostream> #include <cstring> using namespace std; int N, K; int seq[355]; int prefleft[355]; int prefright[355]; int dptable[355][355][355]; bool dp(int i, int j, int k){ if(k == 0){ return dptable[i][j][k] = 0; } if(dptable[i][j][k] != -1){ return dptable[i][j][k]; } if((prefleft[i] + prefright[j] - seq[i] - seq[j] - K + k) >= K){ return dptable[i][j][k] = 1; } if((i + N - j + 1) % 2 == 0){ dptable[i][j][k] = dp(i + 1, j, k - seq[i]) || dp(i, j - 1, k - seq[j]); } else { dptable[i][j][k] = dp(i + 1, j, k) && dp(i, j - 1, k); } return dptable[i][j][k]; } int main(){ cin >> N >> K; for(int i = 0; i < N; i++){ char c; cin >> c; if(c == '\n') cin >> c; if(c == 'C') seq[i] = 1; else seq[i] = 0; } prefleft[0] = seq[0]; for(int i = 1; i < N; i++){ prefleft[i] = seq[i] + prefleft[i - 1]; } prefright[N - 1] = seq[N - 1]; for(int i = N - 2; i >= 0; i--){ prefright[i] = seq[i] + prefright[i + 1]; } memset(dptable, -1, sizeof(dptable)); if(dp(0, N - 1, K)) cout << "DA"; else cout << "NE"; }

Compilation message (stderr)

Main.cpp: In function 'bool dp(int, int, int)':
Main.cpp:13:33: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   13 |         return dptable[i][j][k] = 0;
      |                ~~~~~~~~~~~~~~~~~^~~
Main.cpp:19:33: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   19 |         return dptable[i][j][k] = 1;
      |                ~~~~~~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...