結果
問題 | No.1171 Runs in Subsequences |
ユーザー |
|
提出日時 | 2020-08-14 23:48:32 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,112 bytes |
コンパイル時間 | 749 ms |
コンパイル使用メモリ | 124,672 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-10 16:53:55 |
合計ジャッジ時間 | 1,563 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
#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; }