Submission #632466

# Submission time Handle Problem Language Result Execution time Memory
632466 2022-08-20T05:57:26 Z LeticiaFCS Kamenčići (COCI21_kamencici) C++17
70 / 70
79 ms 175496 KB
#include "bits/stdc++.h"
#define st first
#define nd second
using lint = int64_t;
constexpr int MOD = int(1e9) + 7;
constexpr int INF = 0x3f3f3f3f;
constexpr int NINF = 0xcfcfcfcf;
constexpr lint LINF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
	return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;

int n, k;
vector<int> v, pref;
int dp[355][355][355];

int getRed(int l, int r){
	if(l > r) return 0;
	return pref[r] - pref[l-1];
}

int solve(int l, int r, int q){
	auto &DP = dp[l][r][q];
	if(DP != -1)
		return DP;
	int q_other = getRed(1, l-1) + getRed(r+1, n) - q;
	
	if(q >= k)
		DP = 0;
	else if(q_other >= k)
		DP = 1;
	else if( !solve(l+1, r, q_other) )
		DP = 1;
	else if( !solve(l, r-1, q_other) )
		DP = 1;
	else
		DP = 0;
	//cout<<l<<" "<<r<<" "<<q<<" "<<q_other<<" = "<<DP<<"\n";
	return DP;
}

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	memset(dp, -1, sizeof dp);
	cin>>n>>k;
	v = vector<int>(n+2);
	pref = vector<int>(n+2);
	string s; cin>>s;
	for(int i=0; i<n; i++)
		if(s[i] == 'C')
			v[i+1] = 1; 
	for(int i=1; i<=n+1; i++)
		pref[i] = pref[i-1] + v[i];
	
		
	if(solve(1, n, 0))
		cout<<"DA\n";
	else
		cout<<"NE\n";
	
	return 0;
}
/*
[  ]Leu o problema certo???
[  ]Ver se precisa de long long
[  ]Viu o limite dos fors (é n? é m?)
[  ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[  ]Testar sample
[  ]Testar casos de  borda
[  ]1LL no 1LL << i
[  ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
# Verdict Execution time Memory Grader output
1 Correct 79 ms 175392 KB Output is correct
2 Correct 68 ms 175296 KB Output is correct
3 Correct 64 ms 175316 KB Output is correct
4 Correct 64 ms 175348 KB Output is correct
5 Correct 71 ms 175308 KB Output is correct
6 Correct 66 ms 175368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 175392 KB Output is correct
2 Correct 68 ms 175296 KB Output is correct
3 Correct 64 ms 175316 KB Output is correct
4 Correct 64 ms 175348 KB Output is correct
5 Correct 71 ms 175308 KB Output is correct
6 Correct 66 ms 175368 KB Output is correct
7 Correct 65 ms 175308 KB Output is correct
8 Correct 64 ms 175320 KB Output is correct
9 Correct 66 ms 175496 KB Output is correct
10 Correct 70 ms 175316 KB Output is correct
11 Correct 65 ms 175360 KB Output is correct
12 Correct 65 ms 175308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 175392 KB Output is correct
2 Correct 68 ms 175296 KB Output is correct
3 Correct 64 ms 175316 KB Output is correct
4 Correct 64 ms 175348 KB Output is correct
5 Correct 71 ms 175308 KB Output is correct
6 Correct 66 ms 175368 KB Output is correct
7 Correct 65 ms 175308 KB Output is correct
8 Correct 64 ms 175320 KB Output is correct
9 Correct 66 ms 175496 KB Output is correct
10 Correct 70 ms 175316 KB Output is correct
11 Correct 65 ms 175360 KB Output is correct
12 Correct 65 ms 175308 KB Output is correct
13 Correct 66 ms 175392 KB Output is correct
14 Correct 75 ms 175404 KB Output is correct
15 Correct 67 ms 175308 KB Output is correct
16 Correct 79 ms 175308 KB Output is correct
17 Correct 71 ms 175336 KB Output is correct
18 Correct 66 ms 175404 KB Output is correct