結果

問題 No.346 チワワ数え上げ問題
ユーザー shinwisteriashinwisteria
提出日時 2017-04-01 11:03:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 777 ms / 2,000 ms
コード長 1,069 bytes
コンパイル時間 3,580 ms
コンパイル使用メモリ 75,168 KB
実行使用メモリ 59,956 KB
最終ジャッジ日時 2023-09-22 01:56:27
合計ジャッジ時間 9,744 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
56,196 KB
testcase_01 AC 118 ms
56,036 KB
testcase_02 AC 114 ms
56,268 KB
testcase_03 AC 114 ms
56,168 KB
testcase_04 AC 117 ms
55,892 KB
testcase_05 AC 115 ms
55,980 KB
testcase_06 AC 117 ms
55,728 KB
testcase_07 AC 116 ms
56,156 KB
testcase_08 AC 116 ms
55,808 KB
testcase_09 AC 117 ms
56,240 KB
testcase_10 AC 220 ms
59,620 KB
testcase_11 AC 200 ms
57,532 KB
testcase_12 AC 212 ms
57,796 KB
testcase_13 AC 197 ms
54,840 KB
testcase_14 AC 132 ms
56,204 KB
testcase_15 AC 214 ms
57,096 KB
testcase_16 AC 215 ms
57,648 KB
testcase_17 AC 220 ms
59,452 KB
testcase_18 AC 212 ms
59,576 KB
testcase_19 AC 203 ms
57,600 KB
testcase_20 AC 777 ms
59,564 KB
testcase_21 AC 506 ms
59,956 KB
testcase_22 AC 504 ms
59,756 KB
testcase_23 AC 116 ms
56,468 KB
testcase_24 AC 116 ms
55,720 KB
testcase_25 AC 116 ms
55,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;
public class Chiwawa {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner s = new Scanner(System.in);
		StringBuilder str = new StringBuilder(s.nextLine());
		s.close();
		long all = 0;
		ArrayList<Integer> cp = new ArrayList<>();
		ArrayList<Integer> wp = new ArrayList<>();
		for(int i = str.length()-1;i >= 0;i--){
			if(str.charAt(i) == 'c'){
				cp.add(0, i);
			}else if(str.charAt(i) == 'w'){
				wp.add(0, i);
			}
		}
		int start = 0;
		for(int i:cp){
			int count = 0;
			boolean tf = true;
			for(int j = start;j < wp.size();j++){
				if(wp.get(j) > i){
					count++;
					if(tf){
						start = j;
						tf = false;
					}
				}
				if(count == 2){
					count += (wp.size()-j-1);
					break;
				}
			}
			if(count <2){
				break;
			}else{
				all += Combination(count,2);
			}
		}
		System.out.println(all);

	}
	static long Combination(int r,int q){
		long rCq = 1;
		for(int i = 1;i <= q;i++){
			rCq = rCq * r-- / i;
		}
		return rCq;
	}

}
0