結果

問題 No.346 チワワ数え上げ問題
コンテスト
ユーザー Bantako
提出日時 2017-07-16 21:23:06
言語 C++11
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 102 ms / 2,000 ms
+ 285µs
コード長 506 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 106 ms
コンパイル使用メモリ 40,472 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-10-29 16:39:28
合計ジャッジ時間 2,713 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    5 | main(){
      | ^~~~

ソースコード

diff #
raw source code

#include<stdio.h>
#include<string.h>
int num[100000];
char S[100001];
main(){
    int sum = 0;
    int count = 0;//cの数
    scanf("%s",S);
    for(int i = 0;i < strlen(S);i++){
        if(S[i]=='c'){
            num[count] = sum;
            count++;
        }
        if(S[i]=='w'){
            sum++;
        }
    }
    long long ans = 0;
    for(int i = 0;i < count;i++){
        long long a = sum-num[i];
        if(a >= 2){
            ans += a*(a-1)/2;
        }
    }
    printf("%lld\n",ans);
}
0