結果

問題 No.346 チワワ数え上げ問題
ユーザー iqueue02
提出日時 2019-11-19 21:20:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 502 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 170,384 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-04 08:29:31
合計ジャッジ時間 2,384 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  string s;
  cin >> s;
  int n = sz(s);
  vector<ll> cum(n+1, 0);
  ll res = 0;
  for (int i = n-1; i >= 0; i--) {
    if (s[i] == 'w') cum[i] = cum[i+1] + 1;
    else cum[i] = cum[i+1];
  }
  for (int i = 0; i < n-2; i++) {
    if (s[i] == 'c') res += (cum[i] * (cum[i] - 1)) / 2;
  }
  cout << res << endl;
  return 0;
}
0