結果

問題 No.1171 Runs in Subsequences
ユーザー ShibuyapShibuyap
提出日時 2020-09-19 05:26:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,669 bytes
コンパイル時間 2,604 ms
コンパイル使用メモリ 199,372 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-05 04:48:49
合計ジャッジ時間 4,673 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

// ax + by = gcd(a, b) となるような (x, y) を求める
// a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x); // 再帰
    y -= a / b * x;
    return d;
}


// 負の数に対応した mod
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}


// 逆元計算 (a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // x % m だが、x が負かもしれないので
}

const ll MOD = 1000000007;

int main() {
    string s; cin >> s;
    ll n = s.size();
    ll ans = mod_pow(2,n-1,MOD) * n % MOD;
    rep(_,26){
        char c = 'a' + _;
        ll sum = 0;
        rep(i,n){
            if(s[i] == c){
                ans += MOD - sum;
                ans %= MOD;
                sum += mod_pow(2,n-1,MOD);
            }
            sum = sum * modinv(2,MOD) % MOD;
        }
    }

    cout << ans << endl;
    return 0;
}


0