結果

問題 No.345 最小チワワ問題
ユーザー shinwisteriashinwisteria
提出日時 2017-04-15 15:36:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 4,849 ms
コンパイル使用メモリ 80,268 KB
実行使用メモリ 57,608 KB
最終ジャッジ日時 2023-10-26 04:08:41
合計ジャッジ時間 9,427 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,244 KB
testcase_01 AC 130 ms
55,596 KB
testcase_02 AC 133 ms
57,304 KB
testcase_03 AC 131 ms
57,288 KB
testcase_04 AC 133 ms
57,316 KB
testcase_05 AC 131 ms
57,548 KB
testcase_06 AC 128 ms
57,592 KB
testcase_07 AC 130 ms
57,320 KB
testcase_08 AC 130 ms
57,324 KB
testcase_09 AC 134 ms
57,292 KB
testcase_10 AC 127 ms
57,508 KB
testcase_11 AC 126 ms
57,532 KB
testcase_12 AC 135 ms
57,276 KB
testcase_13 AC 130 ms
57,608 KB
testcase_14 AC 134 ms
57,332 KB
testcase_15 AC 129 ms
57,560 KB
testcase_16 AC 134 ms
57,308 KB
testcase_17 AC 138 ms
57,600 KB
testcase_18 AC 130 ms
57,380 KB
testcase_19 AC 131 ms
57,316 KB
testcase_20 AC 134 ms
57,296 KB
testcase_21 AC 131 ms
57,240 KB
testcase_22 AC 134 ms
57,592 KB
testcase_23 AC 132 ms
57,292 KB
testcase_24 AC 132 ms
57,520 KB
testcase_25 AC 129 ms
57,244 KB
testcase_26 AC 130 ms
57,320 KB
testcase_27 AC 129 ms
57,588 KB
testcase_28 AC 128 ms
57,336 KB
testcase_29 AC 131 ms
57,300 KB
testcase_30 AC 137 ms
57,280 KB
testcase_31 AC 134 ms
57,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
//未完成
import java.util.Scanner;
import java.util.TreeSet;

public class Mincww {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner s = new Scanner(System.in);
		StringBuilder cww = new StringBuilder(s.next());
		s.close();
		TreeSet<Integer> clist = new TreeSet<>();
		ArrayList<Integer> wlist = new ArrayList<>();
		while(cww.indexOf("c") != -1 || cww.indexOf("w") != -1){
			int cn = cww.lastIndexOf("c");
			int wn = cww.lastIndexOf("w");
			if((cn != -1 && Math.max(cn, wn) == cn) || wn == -1){
				clist.add(cn);
				cww.delete(cn,cww.length()+1);
			}else if(cn == -1 || (wn != -1 && Math.max(cn, wn) == wn)){
				wlist.add(0,wn);
				cww.delete(wn,cww.length()+1);
			}
		}
		int count = -1;
		for(int c:clist){
			int k =0;
			for(int i = 0;i < wlist.size();i++){
				if(wlist.get(i) > c){
					k++;
					if(k == 2){
						int a = wlist.get(i)-c+1;
						if(count == -1){
							count = a;
						}else{
							count = Math.min(count, a);
						}
					}
				}
				
			}
		}
		System.out.println(count);
	}
}
0