Submission #1204147

#TimeUsernameProblemLanguageResultExecution timeMemory
1204147cbnhtmanhKamenčići (COCI21_kamencici)C++20
70 / 70
28 ms24136 KiB
/*
    .=#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#=.
   .*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%+
   :%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   =%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
  .+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%=
  .*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%:
  :#%%%%%%%%%#=....-#:......-*%%*:......:**+++++++++++++#%%%#++++++++++++++%*+++++++++++++++%%%%%%#.
  -%%%%%%%%+:......+%#-.....:+#-......:*%#+++++++++++++++*%%*+++++++++++++*%+++++++++++++++*%%%%%%*.
 .=%%%%%%-.........#%%%-...+#-.......+%%%#+++++#####*+++++#%++++++########%%####*+++++#####%%%%%%%=.
 .*%%%%%%:........-%%%%%+-#=.......=%%%%%*+++++%%%%%#+++++%#+++++#%%%%%%%%%%%%%%++++++%%%%%%%%%%%%-.
 :#%%%%%%--*+.....+%%%%%%+........#%%%%%%++++++++++++++++%%*++++++++++++#%%%%%%%+++++*%%%%%%%%%%%#:
.:%%%%%%%%%%=....:#%%%%+...........*%%%%#++++++++++++++++#%+++++++++++++#%%%%%%*+++++%%%%%%%%%%%%*:
.-%%%%%%%%%#:....-%%%*..............=%%%++++++%%%%%%*++++**+++++#%%%%%%%%%%%%%%++++++%%%%%%%%%%%%+.
.+%%%%%%%%%*.....+%#:......:*-.......=%#+++++*#####*+++++#*+++++########%%%%%%#+++++#%%%%%%%%%%%%=.
.*%%%%%%%%%=....:+-.......+%%%+.......-#*+++++++++++++++##++++++++++++++*%%%%%*+++++%%%%%%%%%%%%%-
.%%%%%%%%%%:............+%%%%%%#=.......#*+++++++++++*#%%#++++++++++++++#%%%%%*++++*%%%%%%%%%%%%#-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#:
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*.
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*.
.=#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#=.
*/

#include <bits/stdc++.h>
#define fi(i, a, b) for( int i = a; i <= b; i++ )
#define fid(i, a, b) for( int i = a; i >= b; i-- )
#define getbit(x, i) ((x>>i)&1)
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define st first
#define nd second
#define mp make_pair
#define HTManh ""
#define maxn 100009
#define endl '\n'
using namespace std;

int test;
int n, k;
string s;

int tong[359];

bool dp[359][359][180];
bool xd[359][359][180];

bool calc(int len, int d, int gt)
{
    int c = (d+len-1);
    if (xd[d][c][gt]) return dp[d][c][gt];
    xd[d][c][gt] = 1;
    bool res = 0;
    if (gt >= k) res = 1;
    else if (tong[n] - (tong[c] - tong[d-1]) - gt >= k) res = 0;
    else
    {
        if ((n-len)%2==0)
        {
            int kq1 = calc(len-1,d+1,gt+(s[d]=='C'));
            int kq2 = calc(len-1,d,gt+(s[c]=='C'));
            if (kq1 == 1 && kq2 == 1) res = 1;
            else res = 0;
        }
        else
        {
            int kq1 = calc(len-1,d+1,gt);
            int kq2 = calc(len-1,d,gt);
            if (kq1 == 0 && kq2 == 0) res = 0;
            else res = 1;
        }
    }
    //cout << d << " " << c << " " << gt << ' ' << res << endl;
    return (dp[d][c][gt] = res);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	if (fopen(HTManh".inp", "r"))
    {
        freopen(HTManh".inp", "r", stdin);
        freopen(HTManh".out", "w", stdout);
    }

    cin >> n >> k >> s;
    s = ' ' + s;

    fi(i,1,n) tong[i] = tong[i-1] + (s[i] == 'C');
    cout << (calc(n,1,0) ? "NE" : "DA");
}

Compilation message (stderr)

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