結果

問題 No.346 チワワ数え上げ問題
ユーザー matsuyoshi30matsuyoshi30
提出日時 2018-09-11 23:09:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 414 bytes
コンパイル時間 3,745 ms
コンパイル使用メモリ 71,796 KB
実行使用メモリ 58,392 KB
最終ジャッジ日時 2023-09-06 15:14:23
合計ジャッジ時間 7,369 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
56,392 KB
testcase_01 AC 117 ms
56,332 KB
testcase_02 AC 117 ms
55,832 KB
testcase_03 AC 116 ms
57,760 KB
testcase_04 AC 121 ms
55,392 KB
testcase_05 AC 113 ms
55,712 KB
testcase_06 AC 117 ms
56,336 KB
testcase_07 AC 115 ms
56,016 KB
testcase_08 AC 115 ms
56,064 KB
testcase_09 AC 114 ms
55,984 KB
testcase_10 AC 186 ms
56,484 KB
testcase_11 AC 175 ms
57,184 KB
testcase_12 AC 187 ms
56,752 KB
testcase_13 AC 166 ms
58,392 KB
testcase_14 AC 126 ms
56,264 KB
testcase_15 AC 172 ms
56,416 KB
testcase_16 AC 187 ms
54,596 KB
testcase_17 AC 188 ms
56,616 KB
testcase_18 AC 191 ms
55,940 KB
testcase_19 AC 186 ms
57,620 KB
testcase_20 AC 189 ms
56,372 KB
testcase_21 AC 185 ms
56,196 KB
testcase_22 AC 185 ms
56,092 KB
testcase_23 AC 112 ms
56,096 KB
testcase_24 AC 111 ms
55,788 KB
testcase_25 AC 111 ms
55,812 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();
        long ans = 0;
        long wc = 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