結果

問題 No.346 チワワ数え上げ問題
ユーザー matsuyoshi30matsuyoshi30
提出日時 2018-09-11 23:05:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 420 bytes
コンパイル時間 2,040 ms
コンパイル使用メモリ 72,068 KB
実行使用メモリ 58,904 KB
最終ジャッジ日時 2023-09-06 15:07:16
合計ジャッジ時間 7,708 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
56,312 KB
testcase_01 AC 111 ms
55,976 KB
testcase_02 AC 106 ms
55,820 KB
testcase_03 AC 113 ms
56,012 KB
testcase_04 AC 117 ms
55,684 KB
testcase_05 AC 111 ms
55,828 KB
testcase_06 AC 112 ms
55,772 KB
testcase_07 AC 115 ms
56,120 KB
testcase_08 AC 114 ms
55,848 KB
testcase_09 AC 113 ms
55,728 KB
testcase_10 WA -
testcase_11 AC 167 ms
56,608 KB
testcase_12 WA -
testcase_13 AC 163 ms
56,372 KB
testcase_14 AC 121 ms
56,120 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 171 ms
56,536 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 111 ms
55,672 KB
testcase_24 AC 107 ms
55,928 KB
testcase_25 AC 110 ms
55,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();

        int l = s.length();
        int ans = 0;
        int wc = 0, cc = 0;

        for(int i=l-1; i>=0; i--) {
            if(s.charAt(i) == 'w') wc++;
            if(s.charAt(i) == 'c') ans += wc * (wc-1) / 2;
        }

        System.out.println(ans);
    }
}
0