結果

問題 No.1171 Runs in Subsequences
ユーザー Shun_PIShun_PI
提出日時 2020-08-14 22:04:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 713 ms / 2,000 ms
コード長 1,641 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 166,684 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 21:52:04
合計ジャッジ時間 6,864 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 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 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 594 ms
5,376 KB
testcase_16 AC 588 ms
5,376 KB
testcase_17 AC 623 ms
5,376 KB
testcase_18 AC 636 ms
5,376 KB
testcase_19 AC 643 ms
5,376 KB
testcase_20 AC 634 ms
5,376 KB
testcase_21 AC 713 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
constexpr int MAX = 200001;
lint fact[MAX], finv[MAX], inv[MAX];
void cominit() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  FOR(i, 2, MAX){
    fact[i] = fact[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
lint ncr(lint n, lint r, lint mod) {
  if(n < 0 || r < 0 || n-r < 0) return 0;
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string S;
  cin >> S;
  lint N = S.size();
  vector<lint> tmp(26);
  lint sum = 0;
  REP(i, N) {
    sum = (sum + tmp[S[i]-'a']) % MOD;
    tmp[S[i]-'a'] = (tmp[S[i]-'a'] + power(2, N-1, MOD)) % MOD;
    REP(j, 26) tmp[j] = tmp[j] * power(2, MOD-2, MOD) % MOD;
  }
  lint ans = (N*power(2, N-1, MOD) % MOD - sum + MOD) % MOD;
  cout << ans << endl;
}
0