結果

問題 No.346 チワワ数え上げ問題
ユーザー tubo28
提出日時 2016-03-11 21:12:04
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 517 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 64,776 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 00:54:34
合計ジャッジ時間 1,765 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

string s;

int main(){
    while(cin >> s){
        int n = s.size();
        reverse(begin(s), end(s));
        int cntw = 0;
        long long ans = 0;
        rep(i,n){
            if(s[i] == 'w'){
                cntw++;
            } else if(s[i] == 'c'){
                ans += 1LL*cntw*(cntw-1)/2;
            }
        }
        cout << ans << endl;
    }
}
0