結果

問題 No.346 チワワ数え上げ問題
ユーザー tetsuzuki1115
提出日時 2017-09-28 12:54:11
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 744 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 80,808 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-15 18:13:19
合計ジャッジ時間 1,589 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
        
    string S;
    cin >> S;
    
    vector<long long> W(S.length()+1);
    W[S.length()] = 0;
          
    for ( int i = S.length()-1; i >= 0; i-- ) {
        if ( S[i] == 'w' ) { W[i] = W[i+1]+1; }
        else { W[i] = W[i+1]; }
    }
    
    long long ans = 0;
    for ( int i = 0; i < S.length(); i++ ) {
        if ( S[i] == 'c' ) { ans += W[i+1] * (W[i+1]-1) / 2; }
    }
    
    cout << ans << endl;
    
    return 0;
}
0