結果

問題 No.1171 Runs in Subsequences
ユーザー WarToksWarToks
提出日時 2020-08-14 22:58:11
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,127 bytes
コンパイル時間 4,152 ms
コンパイル使用メモリ 94,676 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-31 23:32:10
合計ジャッジ時間 6,634 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>

constexpr int mod = 1'000'000'007;
constexpr int alpha_size = 'z' - 'a' + 1;

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);
    
    std::string S; std::cin >> S;

    const int n = S.size();

    long long int res = 0, sum_dp = 0, sum_count = 1;

    std::array<long long int, alpha_size> count, dp;
    std::fill(count.begin(), count.end(), 0);
    std::fill(dp.begin(), dp.end(), 0);

    for(int i = 0; i < n; ++i){
        const int kind = S[i] - 'a';

        const long long int next_count = (count[kind] + sum_count) % mod;
        const long long int next_dp = (sum_dp + sum_count - count[kind]) % mod;

        (sum_count *= 2) %= mod;
        (sum_dp += next_dp) %= mod;

        count[kind] = next_count;
        (dp[kind] += next_dp) %= mod;
    }

    for(int i = 0; i < alpha_size; ++i) res += dp[i];
    res %= mod; if(res < 0) res += mod;
    std::cout << res << '\n';

    return 0;
}
0