Submission #647650

# Submission time Handle Problem Language Result Execution time Memory
647650 2022-10-03T13:34:13 Z GudStonks Kamenčići (COCI21_kamencici) C++17
70 / 70
53 ms 51044 KB
#include<bits/stdc++.h>
using namespace std;
int n, k;
string s;
int dp[352][352][352], pr[352];

bool fun(int l = 0, int r = n - 1, int a = 0)
{
	int b = pr[l] + pr[n] - pr[r + 1] - a;
	if(dp[l][r][a] != 0)
		return dp[l][r][a] - 1;
    if(a == k || b == k)
        return b == k;
    if(!((n - (r - l + 1)) & 1))
    {
    	dp[l][r][a] = 1 + (fun(l + 1, r, a + (s[l] == 'C')) || fun(l, r - 1, a + (s[r] == 'C')));
        return dp[l][r][a] - 1;
    }
    else
    {
    	dp[l][r][a] = 1 + (fun(l + 1, r, a) && fun(l, r - 1, a));
        return dp[l][r][a] - 1;
    }
}
int main()
{
    cin>>n>>k;
    cin>>s;
    pr[0] = 0;
    for(int i = 1; i <= n; i++)
    {
    	pr[i] = pr[i - 1] + (s[i - 1] == 'C');
    }
    cout<<(fun() ? "DA" : "NE");
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 952 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 952 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 53 ms 51044 KB Output is correct
15 Correct 19 ms 18388 KB Output is correct
16 Correct 48 ms 47080 KB Output is correct
17 Correct 34 ms 49604 KB Output is correct
18 Correct 16 ms 22100 KB Output is correct