結果

問題 No.1171 Runs in Subsequences
ユーザー WarToksWarToks
提出日時 2020-08-14 23:49:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 1,093 ms
コンパイル使用メモリ 80,736 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 23:20:52
合計ジャッジ時間 1,801 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <iostream>
#include <iomanip>
#include <array>
#include <utility>

constexpr int mod = 1'000'000'007;
constexpr int alpha_size = 'z' - 'a' + 1;
constexpr int MAX_S = 200'000;
char S[MAX_S + 1];

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

    int sum_dp = 0, sum_count = 1;

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

    for(int i = 0; S[i] ; ++i){
        const int kind = S[i] - 'a'; 
        int next_count = count[kind] + sum_count; if(next_count >= mod) next_count -= mod;
        int next_dp = (sum_dp + sum_count - count[kind]);
        if(next_dp < 0) next_dp += mod; else if(next_dp >= mod) next_dp -= mod;

        sum_count <<= 1; if(sum_count >= mod) sum_count -= mod;
        sum_dp += next_dp; if(sum_dp >= mod) sum_dp -= mod;

        count[kind] = next_count;
        dp[kind] += next_dp; if(dp[kind] >= mod) dp[kind] -= mod;
    }
    std::cout << sum_dp << '\n';

    return 0;
}
0