結果

問題 No.346 チワワ数え上げ問題
ユーザー Bantako
提出日時 2017-07-16 21:12:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 500 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 22,784 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-08 04:30:48
合計ジャッジ時間 2,339 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
    5 | main(){
      | ^~~~
main.cpp: In function ‘int main()’:
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |     scanf("%s",S);
      |     ~~~~~^~~~~~~~

ソースコード

diff #

#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++){
        int a = sum-num[i];
        if(a >= 2){
            ans += a*(a-1)/2;
        }
    }
    printf("%lld\n",ans);
}
0