Submission #3654309


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/







int N; string S; int Q;
//---------------------------------------------------------------------------------------------------
ll solve(int K) {
    ll ans = 0;
    int c = 0;
    int Mcnt = 0;
    int Ccnt = 0;
    ll tot = 0;
    rep(a, 0, N) {
        if (S[a] == 'D') {
            while (c < N and c - a < K) {
                if (S[c] == 'M') Mcnt++;
                else if (S[c] == 'C') {
                    Ccnt++;
                    tot += Mcnt;
                }
                c++;
            }
            ans += tot;
        }
        else if (S[a] == 'M') {
            Mcnt--;
            tot -= Ccnt;
        }
        else if (S[a] == 'C') {
            Ccnt--;
        }
    }
    return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> S >> Q;
    rep(q, 0, Q) {
        int k; cin >> k;
        printf("%lld\n", solve(k));
    }
}

Submission Info

Submission Time
Task C - k-DMC
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 600
Code Size 2224 Byte
Status AC
Exec Time 1000 ms
Memory 1948 KB

Judge Result

Set Name All
Score / Max Score 600 / 600
Status
AC × 23
Set Name Test Cases
All dmc-dmc-00, dmc-dmc-01, dmc-dmc-02, dmc-dmc-03, dmc-dmc-04, dmc-large-00, dmc-large-01, dmc-large-02, dmc-large-03, dmc-large-04, dmc-random-00, dmc-random-01, dmc-random-02, dmc-random-03, dmc-random-04, dmc-special-00, dmc-special-01, dmc-special-02, dmc-special-03, sample_01, sample_02, sample_03, sample_04
Case Name Status Exec Time Memory
dmc-dmc-00 AC 995 ms 1948 KB
dmc-dmc-01 AC 998 ms 1948 KB
dmc-dmc-02 AC 993 ms 1948 KB
dmc-dmc-03 AC 997 ms 1948 KB
dmc-dmc-04 AC 1000 ms 1948 KB
dmc-large-00 AC 355 ms 1948 KB
dmc-large-01 AC 356 ms 1948 KB
dmc-large-02 AC 356 ms 1948 KB
dmc-large-03 AC 355 ms 1948 KB
dmc-large-04 AC 357 ms 1948 KB
dmc-random-00 AC 311 ms 1948 KB
dmc-random-01 AC 245 ms 1172 KB
dmc-random-02 AC 202 ms 1948 KB
dmc-random-03 AC 154 ms 1948 KB
dmc-random-04 AC 119 ms 1172 KB
dmc-special-00 AC 222 ms 1948 KB
dmc-special-01 AC 299 ms 1948 KB
dmc-special-02 AC 283 ms 1948 KB
dmc-special-03 AC 226 ms 1948 KB
sample_01 AC 1 ms 256 KB
sample_02 AC 1 ms 256 KB
sample_03 AC 1 ms 256 KB
sample_04 AC 1 ms 256 KB