結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー chiho_miyakochiho_miyako
提出日時 2015-05-08 23:51:02
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,888 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 75,752 KB
実行使用メモリ 58,444 KB
最終ジャッジ日時 2023-08-03 15:05:54
合計ジャッジ時間 10,149 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 124 ms
55,760 KB
testcase_04 AC 125 ms
55,780 KB
testcase_05 AC 123 ms
56,116 KB
testcase_06 AC 124 ms
55,780 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 125 ms
55,676 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 124 ms
55,852 KB
testcase_26 AC 124 ms
56,372 KB
testcase_27 AC 125 ms
55,756 KB
testcase_28 WA -
testcase_29 AC 124 ms
53,640 KB
testcase_30 AC 124 ms
53,956 KB
testcase_31 AC 124 ms
55,696 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 125 ms
55,676 KB
testcase_35 AC 127 ms
55,608 KB
testcase_36 AC 123 ms
55,880 KB
testcase_37 AC 126 ms
55,712 KB
testcase_38 AC 124 ms
56,220 KB
testcase_39 WA -
testcase_40 AC 125 ms
55,664 KB
testcase_41 AC 125 ms
56,372 KB
testcase_42 WA -
testcase_43 AC 125 ms
56,016 KB
testcase_44 AC 123 ms
55,936 KB
testcase_45 AC 123 ms
55,684 KB
testcase_46 AC 126 ms
55,932 KB
testcase_47 WA -
testcase_48 AC 125 ms
55,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Ideone{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner koko = new Scanner(System.in);
        int d = koko.nextInt();
        String one = koko.next();
        String two = koko.next();
        String whole = one + two;
        if(whole.equals("xxxxxxxxxxxxxx")){
        	System.out.println(d);
        }else if(whole.equals("oooooooooooooo")){
        	System.out.println(14);
        }else{
        	String[] on = whole.split("o+");
		    int[] onseq = new int[on.length];
		    int counton = 0;
		    int countoff = 0;
		    int onp =0;
		    int offp =0;
		    for(int i=0; i<on.length; i++){
		    	if(on[i].length()!=0){
		    		onseq[onp++]=on[i].length();
		    		counton++;
		    	}
		    }
		    String[] off = whole.split("x+");
		    int[] offseq = new int[off.length];
		    for(int i=0; i<off.length; i++){
		    	if(off[i].length()!=0){
		    		offseq[offp++]=off[i].length();
		    		countoff++;
		    	}
		    }
		    int max=0;
		    if(countoff>counton){
		    	for(int i=0; i<counton; i++){
		    		if(onseq[i]<=d){
		    			max=Math.max(max, offseq[i]+onseq[i]+offseq[i+1]);
			    	}else{
				    	max=Math.max(max, offseq[i]+d);
					    max=Math.max(max, offseq[i+1]+d);
				    }
			    }
		    }else if(countoff==counton){
		    	if(whole.charAt(0)=='o'){
		    		if(countoff==1){
		    			max=offseq[0]+Math.min(d, onseq[0]);
		    		}else{
		    			for(int i=0; i<counton-1; i++){
		    				if(onseq[i]<=d){
		    					max=Math.max(max, offseq[i]+onseq[i]+offseq[i+1]);
		    				}else{
		    					max=Math.max(max, offseq[i]+d);
		    					max=Math.max(max, offseq[i+1]+d);
		    				}
		    			}
		    			if(onseq[counton-1]<=d){
		    				max=Math.max(max, offseq[counton-1]+onseq[counton-1]);
		    			}else{
		    				max=Math.max(max, offseq[counton-1]+d);
		    			}
		    		}
		    	}else{
		    		max=offseq[0]+Math.min(d, onseq[0]);
		    		for(int i=1; i<counton-1; i++){
		    			if(onseq[i]<=d){
		    				max=Math.max(max, offseq[i-1]+onseq[i]+offseq[i]);
		    			}else{
		    				max=Math.max(max, offseq[i-1]+d);
		    				max=Math.max(max, offseq[i]+d);
		    			}
		    		}
		    	}
		    }else if(countoff<counton){
		    	if(onseq[0]<=d){
		    		max=onseq[0]+offseq[0];
		    	}
			    if(countoff==1){
			    	if(on[1].length()<=d){
			    		max=Math.max(max, offseq[0]+onseq[1]);
			    	}else{
			    		max=Math.max(max, offseq[0]+d);
			    	}
			    }else{
			    	for(int i=1; i<counton-1; i++){
			    		if(onseq[i]<=d){
			    			max=Math.max(max, offseq[i-1]+onseq[i]+offseq[i]);
			    		}else{
			    			max=Math.max(max, offseq[i-1]+d);
			    			max=Math.max(max, offseq[i]+d);
			    		}
			    	}
			    	max=Math.max(max, offseq[countoff-1]+Math.min(d, onseq[counton-1]));
			    }
		    }
		    System.out.println(max);
        }
        
    }
}
0