結果

問題 No.346 チワワ数え上げ問題
ユーザー yun_appyun_app
提出日時 2016-05-09 19:39:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 2,486 ms
コンパイル使用メモリ 74,996 KB
実行使用メモリ 40,616 KB
最終ジャッジ日時 2024-04-15 14:56:48
合計ジャッジ時間 5,146 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
36,888 KB
testcase_01 AC 55 ms
36,940 KB
testcase_02 AC 55 ms
36,688 KB
testcase_03 AC 55 ms
36,824 KB
testcase_04 AC 55 ms
36,656 KB
testcase_05 AC 54 ms
37,032 KB
testcase_06 AC 55 ms
37,036 KB
testcase_07 AC 56 ms
36,964 KB
testcase_08 AC 56 ms
37,004 KB
testcase_09 AC 55 ms
37,036 KB
testcase_10 AC 84 ms
38,476 KB
testcase_11 AC 72 ms
38,040 KB
testcase_12 AC 81 ms
38,444 KB
testcase_13 AC 71 ms
37,840 KB
testcase_14 AC 57 ms
36,984 KB
testcase_15 AC 77 ms
38,552 KB
testcase_16 AC 79 ms
38,012 KB
testcase_17 AC 85 ms
38,232 KB
testcase_18 AC 84 ms
38,652 KB
testcase_19 AC 82 ms
38,084 KB
testcase_20 AC 92 ms
39,964 KB
testcase_21 AC 93 ms
40,468 KB
testcase_22 AC 92 ms
40,616 KB
testcase_23 AC 55 ms
36,820 KB
testcase_24 AC 55 ms
37,036 KB
testcase_25 AC 53 ms
37,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        ArrayList<Long> w_num = new ArrayList<Long>();
        long w_cnt = 0;
        for(int i=line.length()-1;i>=0;i--){
            char c = line.charAt(i);
            if(c == 'c'){
                w_num.add(w_cnt);
            }else if(c == 'w'){
                w_cnt++;
            }
        }
        
        long ans = 0;
        for(long w:w_num){
            ans += combination(w);
        }
        System.out.println(ans);
        
    }
    
    public static long combination(long n){
        return (n * (n-1)) / 2;
    }
}
0