結果

問題 No.1171 Runs in Subsequences
ユーザー ryoissyryoissy
提出日時 2020-08-14 22:26:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 874 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 1,830 ms
コンパイル使用メモリ 166,824 KB
実行使用メモリ 118,736 KB
最終ジャッジ日時 2024-04-18 22:17:27
合計ジャッジ時間 9,918 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
118,272 KB
testcase_01 AC 84 ms
118,528 KB
testcase_02 AC 82 ms
118,376 KB
testcase_03 AC 84 ms
118,272 KB
testcase_04 AC 84 ms
118,400 KB
testcase_05 AC 84 ms
118,400 KB
testcase_06 AC 83 ms
118,284 KB
testcase_07 AC 83 ms
118,272 KB
testcase_08 AC 83 ms
118,272 KB
testcase_09 AC 83 ms
118,296 KB
testcase_10 AC 88 ms
118,316 KB
testcase_11 AC 87 ms
118,400 KB
testcase_12 AC 86 ms
118,400 KB
testcase_13 AC 87 ms
118,296 KB
testcase_14 AC 87 ms
118,516 KB
testcase_15 AC 825 ms
118,608 KB
testcase_16 AC 818 ms
118,732 KB
testcase_17 AC 851 ms
118,480 KB
testcase_18 AC 853 ms
118,736 KB
testcase_19 AC 874 ms
118,476 KB
testcase_20 AC 868 ms
118,604 KB
testcase_21 AC 862 ms
118,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll mod_pow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1){
			res=res*x%MOD;
		}
		x=x*x%MOD;
		n>>=1;
	}
	return res;
}

class segtree{
public:
	static const int N=1<<18;
	ll dp[1<<19];
	segtree(){
		memset(dp,0,sizeof(dp));
	}
	void update(int k,ll v){
		k+=N-1;
		dp[k]+=v;
		while(k>0){
			k=(k-1)/2;
			dp[k]=(dp[k*2+1]+dp[k*2+2])%MOD;
		}
	}

	ll query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		ll vl=query(a,b,k*2+1,l,mid);
		ll vr=query(a,b,k*2+2,mid,r);
		return (vl+vr)%MOD;
	}
};

string s;
ll dp[200005];
ll sum[200005];
segtree seg[28];

int main(void){
	cin >> s;
	int n=s.size();
	ll ans=0;
	dp[0]=1;
	seg[26].update(0,1);
	for(int i=0;i<s.size();i++){
		ll sum=0;
		for(int j=0;j<28;j++){
			ll val=seg[j].query(0,i+1);
			if((s[i]-'a')!=j){
				sum+=val;
				sum%=MOD;
			}
		}
		ans+=sum*mod_pow(2,n-i-1)%MOD;
		ans%=MOD;
		seg[(s[i]-'a')].update(i+1,mod_pow(2,i));
	}
	printf("%lld\n",ans);
	return 0;
}
0