結果

問題 No.346 チワワ数え上げ問題
ユーザー HIcoder
提出日時 2024-03-03 17:33:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 889 ms
コンパイル使用メモリ 100,064 KB
最終ジャッジ日時 2025-02-20 00:16:09
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<P,int> PP;
const ll MOD=1e9+7;



int main(){
    string S;
    cin>>S;
    int N=S.size();
    vector<int> num(N+1,0);
    for(int i=N-1;i>=0;i--){
        num[i]=num[i+1]+(S[i]=='w');
    } 

    ll ans=0;
    for(int i=0;i<N;i++){
        if(S[i]=='c'){
            ll val=1LL*num[i]*(num[i]-1)/2;
            ans+=val;
        }
    }

    cout<<ans<<endl;
}
0