Submission #1185071

#TimeUsernameProblemLanguageResultExecution timeMemory
1185071SmuggingSpunKamenčići (COCI21_kamencici)C++20
70 / 70
9 ms12104 KiB
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
const int lim = 355;
int n, k, pref[lim];
string s;
bitset<lim>vis[lim][lim], f[lim][lim];
bool dp(int l, int r, int c1){
	if(c1 >= k){
		return false;
	}
	if(l > r){
		return true;	
	}
	if(pref[l - 1] + pref[n] - pref[r] - c1 >= k){
		return true;
	}
	if(l == r){
		return false;
	}
	if(vis[l][r].test(c1)){
		return f[l][r].test(c1);
	}
	vis[l][r].set(c1);
	if((dp(l + 2, r, c1 + int(s[l] == 'C')) && dp(l + 1, r - 1, c1 + int(s[l] == 'C'))) || (dp(l, r - 2, c1 + int(s[r] == 'C')) && dp(l + 1, r - 1, c1 + int(s[r] == 'C')))){
		f[l][r].set(c1);
	}
	return f[l][r].test(c1);
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	for(int i = 0; i < lim; i++){
		for(int j = 0; j < lim; j++){
			vis[i][j].reset();
			f[i][j].reset();
		}
	}
	cin >> n >> k >> s;
	s = '#' + s;
	pref[0] = 0;
	for(int i = 1; i <= n; i++){
		pref[i] = pref[i - 1] + int(s[i] == 'C');
	}
	cout << (dp(1, n, 0) ? "DA" : "NE");
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:33:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...