結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー YamaKasaYamaKasa
提出日時 2018-08-17 23:10:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 1,000 ms
コード長 1,804 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 77,120 KB
実行使用メモリ 41,656 KB
最終ジャッジ日時 2024-04-19 07:37:06
合計ジャッジ時間 9,220 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
40,112 KB
testcase_01 AC 116 ms
41,228 KB
testcase_02 AC 111 ms
40,876 KB
testcase_03 AC 115 ms
41,112 KB
testcase_04 AC 110 ms
41,056 KB
testcase_05 AC 113 ms
41,316 KB
testcase_06 AC 99 ms
40,104 KB
testcase_07 AC 101 ms
40,104 KB
testcase_08 AC 98 ms
39,412 KB
testcase_09 AC 100 ms
39,492 KB
testcase_10 AC 98 ms
40,156 KB
testcase_11 AC 118 ms
40,516 KB
testcase_12 AC 112 ms
41,060 KB
testcase_13 AC 107 ms
41,116 KB
testcase_14 AC 104 ms
40,388 KB
testcase_15 AC 116 ms
41,364 KB
testcase_16 AC 103 ms
39,764 KB
testcase_17 AC 124 ms
41,240 KB
testcase_18 AC 122 ms
41,264 KB
testcase_19 AC 133 ms
41,004 KB
testcase_20 AC 129 ms
41,144 KB
testcase_21 AC 114 ms
39,632 KB
testcase_22 AC 136 ms
41,100 KB
testcase_23 AC 128 ms
40,116 KB
testcase_24 AC 132 ms
40,980 KB
testcase_25 AC 123 ms
40,216 KB
testcase_26 AC 142 ms
41,188 KB
testcase_27 AC 118 ms
40,124 KB
testcase_28 AC 137 ms
41,344 KB
testcase_29 AC 136 ms
41,088 KB
testcase_30 AC 125 ms
40,596 KB
testcase_31 AC 135 ms
41,656 KB
testcase_32 AC 127 ms
41,136 KB
testcase_33 AC 133 ms
41,036 KB
testcase_34 AC 120 ms
40,636 KB
testcase_35 AC 133 ms
41,248 KB
testcase_36 AC 134 ms
41,260 KB
testcase_37 AC 121 ms
40,332 KB
testcase_38 AC 115 ms
39,888 KB
testcase_39 AC 127 ms
41,372 KB
testcase_40 AC 113 ms
39,992 KB
testcase_41 AC 107 ms
40,040 KB
testcase_42 AC 120 ms
41,316 KB
testcase_43 AC 107 ms
40,220 KB
testcase_44 AC 122 ms
41,280 KB
testcase_45 AC 132 ms
41,488 KB
testcase_46 AC 112 ms
40,176 KB
testcase_47 AC 113 ms
40,104 KB
testcase_48 AC 109 ms
39,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int D = scan.nextInt();
		String C1 = scan.next();
		String C2 = scan.next();
		scan.close();
		char []c = new char[14];
		for(int i = 0; i < 7; i++) {
			c[i] = C1.charAt(i);
		}
		for(int i = 0; i < 7; i++) {
			c[i + 7] = C2.charAt(i);
		}
		int max = 0;
		for(int i = 0; i < 14; i++) {
			char []b = new char[14];
			for(int j = 0; j < 14; j++) {
				b[j] = c[j];
			}
			for(int j = i; j < i + D; j++) {
				if(j > 13) {
					break;
				}
				if(c[j] == 'x') {
					b[j] = 'o';
				}else {
					break;
				}
			}
			max = Math.max(max, solve(b));
		}
		int cnt1 = 0;
		for(int i = 0; i < 14; i++) {
			if(c[i] == 'o') {
				cnt1 ++;
			}else {
				break;
			}
		}
		int cnt2 = 0;
		for(int i = 13; i >= 0; i--) {
			if(c[i] == 'o') {
				cnt2++;
			}else {
				break;
			}
		}
		max = Math.max(max, cnt1 + D);
		max = Math.max(max, cnt2 + D);
		int cnt3 = 0;
		for(int i = 0; i < 14; i++) {
			if(c[i] == 'x') {
				cnt3 ++;
			}else {
				break;
			}
		}
		int cnt4 = 0;
		for(int i = 13; i >= 0; i--) {
			if(c[i] == 'x') {
				cnt4 ++;
			}else {
				break;
			}
		}
		if(cnt3 <= D) {
			int cnt5 = 0;
			for(int i = cnt3; i < 14; i++) {
				if(c[i] == 'o') {
					cnt5++;
				}else {
					break;
				}
			}
			max = Math.max(max, D + cnt5);
		}
		if(cnt4 <= D) {
			int cnt6 = 0;
			for(int i = 13 - cnt4; i >= 0; i--) {
				if(c[i] == 'o') {
					cnt6++;
				}else {
					break;
				}
			}
			max = Math.max(max, D + cnt6);
		}
		System.out.println(max);
	}
	static int solve(char []c) {
		int k = 0;
		int max = 0;
		for(int i = 0; i < 14; i++) {
			if(c[i] == 'o') {
				k++;
			}else {
				k = 0;
			}
			if(max < k) {
				max = k;
			}
		}
		return max;
	}
}
0