結果

問題 No.346 チワワ数え上げ問題
ユーザー atkrymatkrym
提出日時 2016-10-22 18:43:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 715 bytes
コンパイル時間 2,341 ms
コンパイル使用メモリ 74,776 KB
実行使用メモリ 42,904 KB
最終ジャッジ日時 2024-05-02 22:15:24
合計ジャッジ時間 6,424 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
40,980 KB
testcase_01 AC 109 ms
41,140 KB
testcase_02 AC 104 ms
41,080 KB
testcase_03 AC 113 ms
41,096 KB
testcase_04 AC 105 ms
41,144 KB
testcase_05 AC 109 ms
41,544 KB
testcase_06 AC 116 ms
41,128 KB
testcase_07 AC 117 ms
40,784 KB
testcase_08 AC 104 ms
41,108 KB
testcase_09 AC 100 ms
41,132 KB
testcase_10 AC 163 ms
42,348 KB
testcase_11 AC 152 ms
42,040 KB
testcase_12 AC 181 ms
42,232 KB
testcase_13 AC 147 ms
41,460 KB
testcase_14 AC 113 ms
41,232 KB
testcase_15 AC 165 ms
42,064 KB
testcase_16 AC 173 ms
41,980 KB
testcase_17 AC 175 ms
42,060 KB
testcase_18 AC 173 ms
42,540 KB
testcase_19 AC 171 ms
41,928 KB
testcase_20 AC 170 ms
42,160 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 105 ms
41,136 KB
testcase_24 AC 104 ms
41,060 KB
testcase_25 AC 112 ms
41,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;
import java.text.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String s = sc.next();
        int l = s.length();
        int[] ary = new int[l];
        
        int cnt = 0;
        for (int i = l-1;i >= 0;i--) {
            if (s.charAt(i) == 'w') cnt++;
            ary[i] = cnt;
        }
        
        long ret = 0;
        for (int i = 0;i < l;i++) {
            if (s.charAt(i) == 'c' && ary[i] >= 2) ret += comb(ary[i]);
        }
        
        System.out.println(ret);
    }
    
    private static long comb(int i) {
        return i * (i-1) / 2;
    }
}
0