結果

問題 No.1171 Runs in Subsequences
ユーザー karinohito
提出日時 2024-09-11 15:35:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 586 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 196,800 KB
最終ジャッジ日時 2025-02-24 06:39:49
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;

#include<atcoder/modint>
using namespace atcoder;
using mint =modint1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string S;
    cin>>S;
    int N=S.size();
    vector<mint> TP(N+1,1);
    for(int i=0;i<N;i++)TP[i+1]=TP[i]*2;
    vector<mint> P(26,0);
    mint an=TP[N]-1;
    for(int i=0;i<N;i++){
        for(char c='a';c<='z';c++){
            if(c==S[i])continue;
            an+=P[c-'a']*TP[N-i-1];
        }
        P[S[i]-'a']+=TP[i];
    }
    cout<<an.val()<<endl;
}
0