結果

問題 No.346 チワワ数え上げ問題
ユーザー Bantako
提出日時 2017-07-16 21:23:06
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 506 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 22,656 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-08 04:31:59
合計ジャッジ時間 2,217 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
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++){
        long long a = sum-num[i];
        if(a >= 2){
            ans += a*(a-1)/2;
        }
    }
    printf("%lld\n",ans);
}
0