結果
| 問題 |
No.1171 Runs in Subsequences
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2020-08-14 22:33:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 843 bytes |
| コンパイル時間 | 947 ms |
| コンパイル使用メモリ | 90,136 KB |
| 最終ジャッジ日時 | 2025-01-13 00:14:58 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
constexpr int P = 1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n = s.size();
ll p[26] = {}, q[26] = {};
for (int i = 0; i < n; i++) {
int x = s[i] - 'a';
ll t = 0;
for (int c = 0; c < 26; c++) {
t += q[c] + (c != x) * p[c];
}
q[x] += t;
q[x]++;
q[x] %= P;
t = 0;
for (int c = 0; c < 26; c++) {
t += p[c];
}
p[x] += t;
p[x]++;
p[x] %= P;
}
ll r = 0;
for (int c = 0; c < 26; c++) {
r += q[c];
}
cout << r % P << endl;
return 0;
}
merom686