結果

問題 No.346 チワワ数え上げ問題
ユーザー tokizo
提出日時 2018-05-12 17:13:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 971 bytes
コンパイル時間 2,316 ms
コンパイル使用メモリ 170,404 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-28 09:37:34
合計ジャッジ時間 2,903 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    string t = "";
    REP(i, s.size()){
        if(s[i] == 'c' or s[i] == 'w') t += s[i];
    }
    
    vector<int> A(t.size(), 0);
    int c = 0, w = 0, endw = 1e9;
    REP(i, t.size()){
        if(t[i] == 'c'){
            A[i] = c + 1;
            c++;
        }else{
            A[i] = w + 1;
            w++;
            endw = i;
        }
    }
    
    if(endw == 1e9){
        cout << 0 << endl;
        return 0;
    }

    int ans = 0;
    REP(i, t.size()){
        if(t[i] == 'c'){
            for(int j = i + 1; j < t.size(); j++){
                if(t[j] == 'w'){
                    int r = A[endw] - A[j] + 1;
                    ans += r * (r - 1) / 2;
                    break;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}
0