結果

問題 No.346 チワワ数え上げ問題
ユーザー GrenacheGrenache
提出日時 2016-02-26 22:36:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 649 bytes
コンパイル時間 3,803 ms
コンパイル使用メモリ 75,256 KB
実行使用メモリ 59,996 KB
最終ジャッジ日時 2023-10-24 05:00:56
合計ジャッジ時間 9,305 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
57,404 KB
testcase_01 AC 125 ms
57,384 KB
testcase_02 AC 122 ms
57,316 KB
testcase_03 AC 120 ms
57,116 KB
testcase_04 AC 126 ms
57,504 KB
testcase_05 AC 122 ms
57,388 KB
testcase_06 AC 127 ms
57,344 KB
testcase_07 AC 114 ms
56,220 KB
testcase_08 AC 126 ms
57,376 KB
testcase_09 AC 126 ms
57,256 KB
testcase_10 AC 217 ms
59,996 KB
testcase_11 AC 187 ms
57,652 KB
testcase_12 AC 193 ms
57,952 KB
testcase_13 AC 187 ms
57,620 KB
testcase_14 AC 131 ms
57,504 KB
testcase_15 AC 199 ms
57,608 KB
testcase_16 AC 204 ms
57,604 KB
testcase_17 AC 207 ms
59,832 KB
testcase_18 AC 203 ms
59,848 KB
testcase_19 AC 200 ms
57,748 KB
testcase_20 AC 205 ms
59,844 KB
testcase_21 AC 206 ms
59,768 KB
testcase_22 AC 207 ms
59,856 KB
testcase_23 AC 130 ms
57,380 KB
testcase_24 AC 121 ms
57,332 KB
testcase_25 AC 121 ms
57,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder346 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] s = sc.next().toCharArray();
        int n = s.length;

        int[] cnt = new int[n + 1];
        for (int i = n - 1; i >= 0; i--) {
    		cnt[i] = cnt[i + 1];
        	if (s[i] == 'w') {
        		cnt[i]++;
        	}
        }

        long ret = 0;
        for (int i = 0; i < n; i++) {
        	if (s[i] == 'c' && cnt[i + 1] >= 2) {
        		ret += (long)cnt[i + 1] * (cnt[i + 1] - 1) / 2;
        	}
        }

        System.out.println(ret);

        sc.close();
    }
}
0