結果

問題 No.346 チワワ数え上げ問題
ユーザー utouto97utouto97
提出日時 2019-02-09 18:32:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 1,229 ms
コンパイル使用メモリ 146,872 KB
実行使用メモリ 5,936 KB
最終ジャッジ日時 2023-09-14 11:47:54
合計ジャッジ時間 2,396 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,496 KB
testcase_01 AC 4 ms
4,400 KB
testcase_02 AC 4 ms
4,576 KB
testcase_03 AC 4 ms
4,668 KB
testcase_04 AC 4 ms
4,520 KB
testcase_05 AC 4 ms
4,396 KB
testcase_06 AC 4 ms
4,644 KB
testcase_07 AC 4 ms
4,436 KB
testcase_08 AC 4 ms
4,628 KB
testcase_09 AC 4 ms
4,560 KB
testcase_10 AC 7 ms
5,692 KB
testcase_11 AC 5 ms
5,196 KB
testcase_12 AC 6 ms
5,428 KB
testcase_13 AC 5 ms
5,220 KB
testcase_14 AC 4 ms
4,520 KB
testcase_15 AC 6 ms
5,472 KB
testcase_16 AC 6 ms
5,492 KB
testcase_17 AC 6 ms
5,936 KB
testcase_18 AC 6 ms
5,724 KB
testcase_19 AC 6 ms
5,532 KB
testcase_20 AC 6 ms
5,792 KB
testcase_21 AC 7 ms
5,724 KB
testcase_22 AC 7 ms
5,732 KB
testcase_23 AC 4 ms
4,384 KB
testcase_24 AC 4 ms
4,396 KB
testcase_25 AC 4 ms
4,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

ll power(ll b, ll p)
{
  if(p == 0) return 1;
  return power(b*b%mod, p/2) * (p%2 ? b : 1) % mod;
}

vl fac(100001), finv(100001);

ll comb(ll n, ll r)
{
  return fac[n]*finv[n-r]%mod*finv[r]%mod;
}

signed main()
{
  fac[0] = fac[1] = 1;
  repi(i, 2, 100001) fac[i] = fac[i-1] * i % mod;
  finv[100000] = power(fac[100000], mod-2);
  for(int i = 100000; i > 0; i--) finv[i-1] = finv[i] * i % mod;

  string s;
  cin >> s;
  int n = s.size();

  vi cnt(n, 0);
  for(int i = n-1; i > 0; i--){
    cnt[i-1] += cnt[i] + (s[i] == 'w');
  }

  ll ans = 0;
  rep(i, n){
    if(s[i] == 'c' and cnt[i] >= 2){
 //     ans += comb(cnt[i], 2);
      ans += cnt[i]*(cnt[i]-1)/2;
    }
  }

  cout << ans << endl;

  return 0;
}
0