답안 #988677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988677 2024-05-25T13:57:56 Z coolboy19521 Kamenčići (COCI21_kamencici) C++17
0 / 70
1 ms 512 KB
// Untill Addiction Stops.

# pragma GCC optimize("Ofast")
# include <bits/stdc++.h>

namespace ddr {
    # define bpc(bt) __builtin_popcountll(bt)
    # define bcl(bt) __builtin_clz(bt)
    # define alr(v) rbegin(v), rend(v)
    # define all(v) begin(v), end(v)
    # define si(v) ((ll)v.size())
    # define lob lower_bound
    # define upb upper_bound
    # define pub push_back
    # define pob pop_back
    # define mp make_pair
    # define ins insert
    # define se second
    # define fi first

    template <class T, size_t N> using ar = std::array <T, N>;
    template <class T, class U> using pi = std::pair <T, U>;
    template <class T> using pq = std::priority_queue <T>;
    template <class T> using mt = std::multiset <T>;
    template <class T> using ve = std::vector <T>;
    template <class T> using qu = std::queue <T>;
    typedef std::string str;
    typedef long double ld;
    typedef long long ll;
    typedef bool bo;
    typedef char ch;

    using namespace std;

    const ll inf = 1e18 + 18;
    const ll sz = 3e5 + 15;
    const ll md = 1e9 + 7;
    const ll mo = 998244353;
}

using namespace ddr;

const ll sm = 4e2 + 8;

bo dp[2][sm][sm];
ll n, k;
str s;

bo cac(ll tr, ll le, ll ri, ll ac, ll dc) {
    bo leq = 'C' == s[le];
    bo req = 'C' == s[ri];

    if (k == ac) {
        return !tr;
    }

    if (k == dc) {
        return tr;
    }

    if (dp[tr][le][ri]) {
        return !dp[tr][le][ri];
    }

    bo f = true;

    if (tr) {
        f &= cac(1 - tr, le + 1, ri, ac + leq, dc);
        f &= cac(1 - tr, le, ri - 1, ac + req, dc);
    } else {
        f &= cac(1 - tr, le + 1, ri, ac, dc + leq);
        f &= cac(1 - tr, le, ri - 1, ac, dc + req);
    }

    return !(dp[tr][le][ri] = f);
}

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);

    cin >> n >> k >> s;

    cac(0, 0, n - 1, 0, 0);

    bo le = dp[1][0][n - 2];
    bo ri = dp[1][1][n - 1];

    cout << ((le || ri) ? "DA" : "NE");
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -