結果
問題 |
No.1171 Runs in Subsequences
|
ユーザー |
|
提出日時 | 2025-07-02 09:48:56 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 640 bytes |
コンパイル時間 | 2,942 ms |
コンパイル使用メモリ | 278,768 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-07-02 09:49:01 |
合計ジャッジ時間 | 4,235 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int K = 26; const int md = 1e9 + 7; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); string S; cin >> S; vector<pair<int,int>> dp(K); for(char ch: S) { auto[sum, cnt] = dp[ch - 'a']; sum += sum; cnt += cnt; sum %= md, cnt %= md; for(int j = 0; j < 26; j++) if(ch - 'a' != j) { cnt += dp[j].second; sum += (dp[j].first + dp[j].second) % md; cnt %= md, sum %= md; } sum += 1, cnt += 1; dp[ch - 'a'] = {sum % md, cnt % md}; } int ans = 0; for(int i = 0; i < 26; i++) { ans += dp[i].first; ans %= md; } cout << ans << "\n"; }