結果

問題 No.1171 Runs in Subsequences
ユーザー 夜
提出日時 2020-11-17 15:14:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 723 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 78,432 KB
実行使用メモリ 6,860 KB
最終ジャッジ日時 2023-09-30 14:14:30
合計ジャッジ時間 1,924 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
long long l[200020];
long long r[200020];
long long sum[30] = {};
int main() {
	string s;
	cin >> s;
	long long n = s.size();
	long long t = 1;
	for (int i = 0; i < n; i++) {
		l[i] = t;
		r[n - i - 1] = t;
		t *= 2;
		t %= 1000000007;
	}
	long long ans = 1;
	for (int i = 1; i < n; i++) {
		ans *= 2;
		ans %= 1000000007;
	}
	ans *= n;
	ans %= 1000000007;
	for (int i = 0; i < n; i++) {
		int num = int(s[i] - 'a');
		ans -= sum[num] * r[i] % 1000000007;
		sum[num] += l[i];
		sum[num] %= 1000000007;
		ans %= 1000000007;
	}
	if (ans < 0) {
		ans += 1000000007;
	}
	cout << ans << endl;
}
0