結果

問題 No.346 チワワ数え上げ問題
ユーザー atkrymatkrym
提出日時 2016-10-22 18:47:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 722 bytes
コンパイル時間 1,866 ms
コンパイル使用メモリ 74,208 KB
実行使用メモリ 42,788 KB
最終ジャッジ日時 2024-05-02 22:15:46
合計ジャッジ時間 6,257 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
40,232 KB
testcase_01 AC 111 ms
41,100 KB
testcase_02 AC 107 ms
41,288 KB
testcase_03 AC 107 ms
40,236 KB
testcase_04 AC 98 ms
41,240 KB
testcase_05 AC 104 ms
41,468 KB
testcase_06 AC 110 ms
41,056 KB
testcase_07 AC 109 ms
41,344 KB
testcase_08 AC 103 ms
41,008 KB
testcase_09 AC 114 ms
41,824 KB
testcase_10 AC 169 ms
42,604 KB
testcase_11 AC 143 ms
41,980 KB
testcase_12 AC 165 ms
42,492 KB
testcase_13 AC 153 ms
41,976 KB
testcase_14 AC 131 ms
41,452 KB
testcase_15 AC 166 ms
42,636 KB
testcase_16 AC 170 ms
42,648 KB
testcase_17 AC 172 ms
42,656 KB
testcase_18 AC 169 ms
42,236 KB
testcase_19 AC 166 ms
42,788 KB
testcase_20 AC 178 ms
42,456 KB
testcase_21 AC 172 ms
42,732 KB
testcase_22 AC 176 ms
42,300 KB
testcase_23 AC 97 ms
41,396 KB
testcase_24 AC 95 ms
41,452 KB
testcase_25 AC 107 ms
41,392 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((long)ary[i]);
        }
        
        System.out.println(ret);
    }
    
    private static long comb(long i) {
        return i * (i-1) / 2;
    }
}
0