結果

問題 No.1171 Runs in Subsequences
ユーザー boutarouboutarou
提出日時 2020-08-14 22:03:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 1,615 ms
コンパイル使用メモリ 164,484 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 21:50:47
合計ジャッジ時間 3,530 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

/**
*    author:  boutarou
*    created: 14.08.2020 21:56:06
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
using ll = long long;
using P = pair<int, int>;

const ll MOD = 1e9 + 7;

long long mod_pow(long long n, long long p, long long m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        long long t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}

int main() {
    string s;
    cin >> s;
    vector<int>a(26, 0);
    ll ans = 0;
    rep(i, s.size()) {
        ans += mod_pow(2, s.size() - 1 - i, MOD) * (mod_pow(2, i, MOD) - a[s[i] - 'a']);
        // cout << ans << endl;
        ans %= MOD;
        a[s[i] - 'a'] += mod_pow(2, i, MOD);
        a[s[i] - 'a'] %= MOD;
    }
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << endl;
    return 0;
}
0