結果

問題 No.1171 Runs in Subsequences
ユーザー 👑 ygussanyygussany
提出日時 2020-08-14 22:23:06
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 935 ms
コンパイル使用メモリ 31,232 KB
実行使用メモリ 25,472 KB
最終ジャッジ日時 2024-04-18 22:14:24
合計ジャッジ時間 1,752 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
22,144 KB
testcase_01 AC 16 ms
22,144 KB
testcase_02 AC 14 ms
22,144 KB
testcase_03 AC 14 ms
22,144 KB
testcase_04 AC 15 ms
22,016 KB
testcase_05 AC 15 ms
22,144 KB
testcase_06 AC 15 ms
22,144 KB
testcase_07 AC 15 ms
22,016 KB
testcase_08 AC 16 ms
22,144 KB
testcase_09 AC 15 ms
22,016 KB
testcase_10 AC 16 ms
22,144 KB
testcase_11 AC 15 ms
22,016 KB
testcase_12 AC 15 ms
22,144 KB
testcase_13 AC 15 ms
22,016 KB
testcase_14 AC 15 ms
22,144 KB
testcase_15 AC 22 ms
25,344 KB
testcase_16 AC 22 ms
25,216 KB
testcase_17 AC 22 ms
25,344 KB
testcase_18 AC 23 ms
25,472 KB
testcase_19 AC 23 ms
25,472 KB
testcase_20 AC 22 ms
25,344 KB
testcase_21 AC 23 ms
25,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define Mod 1000000007

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	char S[200001];
	scanf("%s", S);
	
	int i, j, l, pos[26][200001] = {}, k[26] = {};
	long long pow[200001], pow_inv[200001];
	for (l = 0; S[l] != 0; l++) pos[S[l] - 'a'][k[S[l] - 'a']++] = l;
	for (i = 1, pow[0] = 1; i <= l; i++) pow[i] = pow[i-1] * 2 % Mod;
	for (i = l - 1, pow_inv[l] = div_mod(1, pow[l], Mod); i >= 0; i--) pow_inv[i] = pow_inv[i+1] * 2 % Mod;
	
	long long ans = l * pow[l-1] % Mod, tmp;
	for (i = 0; i < 26; i++) {
		for (j = 1, tmp = 0; j < k[i]; j++) {
			tmp = (tmp * pow_inv[pos[i][j] - pos[i][j-1]] % Mod + pow[l - (pos[i][j] - pos[i][j-1] + 1)]) % Mod;
			ans = (ans - tmp + Mod) % Mod;
		}
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}
0