KLab株式会社 採用情報

予選A-B かぶりん! 解説

基本的にはルールを忠実に実装すれば正解です。

問題では0.5秒単位で時間が出てきますが実際にプログラムを書く際は1秒単位のループで十分です。

ダメージの合計が32bit符号付き整数に納まらないため、64bit整数を使うと良いでしょう。

注意すべき点

C++言語での解答例です

#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;

int main() {
    string S; cin >> S; 
    vector<long long> D(1000100);
    vector<int> K(1000100);
    long long damage = 0;
    int kaburin = 5;
    int combo = 0;
    int wait = 0;
    for(int t = 0; t < 1000100; ++t) {
        char c = (t < S.size()) ? S[t] : '-';
        wait = max(0, wait-1);
        damage += D[t];
        kaburin += K[t];
        combo += !!D[t];
        if(wait == 0) {
            if(c == 'N' && kaburin >= 1) {
                kaburin--;
                K[t+7]++;
                D[t+2] += 10LL + 1LL * (combo/10LL);
                wait++;
            }
            if(c == 'C' && kaburin >= 3) {
                kaburin -= 3;
                K[t+9] += 3;
                D[t+4] += 50LL + 5LL * (combo/10LL);
                wait += 3;
            }
        }
    }
    cout << damage << endl;
    return 0;
}