結果

問題 No.346 チワワ数え上げ問題
ユーザー Mcpu3Mcpu3
提出日時 2018-09-26 16:44:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 1,740 ms
コンパイル使用メモリ 74,664 KB
実行使用メモリ 56,664 KB
最終ジャッジ日時 2024-04-19 13:43:08
合計ジャッジ時間 6,277 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
54,544 KB
testcase_01 AC 105 ms
53,036 KB
testcase_02 AC 98 ms
52,880 KB
testcase_03 AC 108 ms
53,992 KB
testcase_04 AC 110 ms
54,188 KB
testcase_05 AC 99 ms
52,816 KB
testcase_06 AC 98 ms
52,716 KB
testcase_07 AC 100 ms
52,764 KB
testcase_08 AC 112 ms
54,156 KB
testcase_09 AC 115 ms
54,316 KB
testcase_10 AC 167 ms
56,376 KB
testcase_11 AC 165 ms
54,516 KB
testcase_12 AC 182 ms
54,740 KB
testcase_13 AC 163 ms
54,096 KB
testcase_14 AC 129 ms
53,900 KB
testcase_15 AC 163 ms
54,268 KB
testcase_16 AC 170 ms
54,476 KB
testcase_17 AC 172 ms
56,132 KB
testcase_18 AC 176 ms
56,664 KB
testcase_19 AC 180 ms
56,480 KB
testcase_20 AC 189 ms
56,572 KB
testcase_21 AC 177 ms
56,636 KB
testcase_22 AC 176 ms
56,432 KB
testcase_23 AC 101 ms
54,080 KB
testcase_24 AC 112 ms
53,896 KB
testcase_25 AC 112 ms
54,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();
        int length = S.length();
        long cum[] = new long[length], ans = 0;
        if (S.charAt(length - 1) == 'w') cum[length - 1] = 1;
        else cum[length - 1] = 0;
        for (int i = length - 2; 0 <= i; --i) {
            if (S.charAt(i) == 'w') cum[i] = cum[i + 1] + 1;
            else cum[i] = cum[i + 1];
        }
        for (int i = 0; i < length; ++i) {
            if (S.charAt(i) == 'c') ans += ((cum[i] - 1) * cum[i]) / 2;
        }
        System.out.print(ans);
    }
}
0