結果

問題 No.346 チワワ数え上げ問題
ユーザー shinwisteria
提出日時 2017-04-01 11:03:00
言語 Java
(openjdk 23)
結果
AC  
実行時間 641 ms / 2,000 ms
コード長 1,069 bytes
コンパイル時間 2,970 ms
コンパイル使用メモリ 78,988 KB
実行使用メモリ 46,992 KB
最終ジャッジ日時 2024-07-07 18:46:02
合計ジャッジ時間 8,231 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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