結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー r.suzukir.suzuki
提出日時 2015-12-31 22:57:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,454 bytes
コンパイル時間 3,128 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 50,632 KB
最終ジャッジ日時 2024-04-21 15:01:17
合計ジャッジ時間 6,811 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
37,092 KB
testcase_01 AC 49 ms
36,812 KB
testcase_02 AC 49 ms
37,268 KB
testcase_03 AC 48 ms
36,788 KB
testcase_04 AC 48 ms
37,188 KB
testcase_05 AC 51 ms
37,180 KB
testcase_06 AC 52 ms
37,108 KB
testcase_07 AC 51 ms
37,312 KB
testcase_08 AC 49 ms
36,960 KB
testcase_09 AC 50 ms
37,308 KB
testcase_10 AC 50 ms
37,128 KB
testcase_11 AC 51 ms
36,808 KB
testcase_12 AC 48 ms
36,964 KB
testcase_13 AC 49 ms
37,304 KB
testcase_14 AC 48 ms
37,420 KB
testcase_15 AC 53 ms
37,204 KB
testcase_16 AC 50 ms
37,140 KB
testcase_17 AC 50 ms
36,816 KB
testcase_18 AC 49 ms
37,244 KB
testcase_19 AC 51 ms
37,148 KB
testcase_20 AC 51 ms
37,340 KB
testcase_21 AC 50 ms
36,984 KB
testcase_22 AC 50 ms
37,136 KB
testcase_23 AC 49 ms
37,288 KB
testcase_24 AC 51 ms
37,116 KB
testcase_25 AC 52 ms
36,832 KB
testcase_26 AC 50 ms
37,284 KB
testcase_27 AC 52 ms
37,292 KB
testcase_28 AC 50 ms
37,212 KB
testcase_29 AC 50 ms
37,036 KB
testcase_30 AC 50 ms
36,956 KB
testcase_31 AC 52 ms
37,192 KB
testcase_32 AC 51 ms
37,180 KB
testcase_33 AC 55 ms
37,152 KB
testcase_34 AC 50 ms
37,280 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 49 ms
37,096 KB
testcase_38 AC 50 ms
37,036 KB
testcase_39 AC 51 ms
37,320 KB
testcase_40 WA -
testcase_41 AC 49 ms
37,056 KB
testcase_42 AC 50 ms
37,220 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 51 ms
36,956 KB
testcase_46 AC 52 ms
37,048 KB
testcase_47 AC 50 ms
37,064 KB
testcase_48 AC 49 ms
37,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class No_204 {
	static char holiday;
	static char weekday;

	// 連続する平日の数を返すメソッド
	static int countWeekday(StringBuilder sb, int i, int c, int v) {
		/*
		 * 最後の文字が渡されたとき、 または判定箇所の文字がholidayだった時、 または連続する休日数が有休数を超えた時終了する。
		 */
		if (i == sb.length() - 1 || sb.charAt(i + 1) == holiday || c >= v) {
			return c;
		} else {
			return countWeekday(sb, ++i, ++c, v);
		}
	}

	// 連続する休日の数を返すメソッド
	static int countHoliday(StringBuilder sb, int i, int c) {
		/*
		 * 最後の文字が渡されたとき、 または判定箇所の文字がweekdayだった時終了する。
		 */
		if (i == sb.length() - 1 || sb.charAt(i + 1) == weekday) {
			return c;
		} else {
			return countHoliday(sb, ++i, ++c);
		}
	}

	// 連続する休日の最大数を返すメソッド
	static int countMaxHoliday(StringBuilder sb, int c) {
		int max = 0;
		for (int i = 0; i < sb.length();) {
			if (sb.charAt(i) == holiday) {
				int m = countHoliday(sb, i, 1);
				max = Math.max(max, m);
				i += m;
			} else {
				i++;
			}
		}
		return max;
	}

	public static void main(String[] args) throws IOException {
		ArrayList<StringBuilder> list = new ArrayList<StringBuilder>();
		InputStreamReader in = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(in);

		int vacation = Integer.parseInt(br.readLine());
		StringBuilder calendar = new StringBuilder(br.readLine() + br.readLine());
		holiday = 'o';
		weekday = 'x';
		int maxHoliday = 0;

		// 2週間の前後に有休の数だけ平日を追加
		for (int i = 0; i < vacation; i++) {
			calendar.insert(0, weekday);
			calendar.append(weekday);
		}

		for (int i = 0; i < calendar.length(); i++) {
			if (calendar.charAt(i) == weekday) {
				int count = countWeekday(calendar, i, 1, vacation);
				StringBuilder weeks = new StringBuilder(calendar);// コピーを作成
				for (int j = 0; j < count; j++) {
					weeks.setCharAt(i + j, holiday);
				}
				list.add(weeks);// コピーをリストに格納
			}
		}

		for (int i = 0; i < list.size(); i++) {
			int m = countMaxHoliday(list.get(i), 0);
			maxHoliday = Math.max(maxHoliday, m);
		}
		System.out.println(maxHoliday);
		br.close();

	}

}
0