結果

問題 No.346 チワワ数え上げ問題
ユーザー iqueue02
提出日時 2019-11-19 21:22:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 463 bytes
コンパイル時間 1,300 ms
コンパイル使用メモリ 170,640 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-04 08:33:51
合計ジャッジ時間 2,067 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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];

    if (s[i] == 'c') res += cum[i] * (cum[i] - 1) / 2;
  }
  cout << res << endl;
  return 0;
}
0