結果

問題 No.608 God's Maze
ユーザー 37zigen37zigen
提出日時 2017-12-23 08:57:10
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,618 bytes
コンパイル時間 2,472 ms
コンパイル使用メモリ 76,608 KB
実行使用メモリ 56,220 KB
最終ジャッジ日時 2023-08-22 16:15:19
合計ジャッジ時間 11,399 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 125 ms
55,836 KB
testcase_04 WA -
testcase_05 AC 124 ms
55,916 KB
testcase_06 WA -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 123 ms
55,968 KB
testcase_11 AC 125 ms
55,812 KB
testcase_12 AC 124 ms
56,156 KB
testcase_13 AC 124 ms
56,012 KB
testcase_14 WA -
testcase_15 AC 123 ms
55,772 KB
testcase_16 AC 123 ms
56,048 KB
testcase_17 AC 124 ms
55,896 KB
testcase_18 AC 123 ms
56,044 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 122 ms
55,652 KB
testcase_26 AC 126 ms
55,524 KB
testcase_27 AC 126 ms
55,652 KB
testcase_28 AC 126 ms
55,928 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String S = sc.next();
		boolean[] a = new boolean[S.length()];
		for (int i = 0; i < S.length(); ++i) {
			a[i] = S.charAt(i) == '.';
		}
		int ans = solve(Arrays.copyOf(a, a.length), n);
		{
			int s = 0;
			int t = a.length - 1;
			while (s < t) {
				boolean tmp = a[s];
				a[s] = a[t];
				a[t] = tmp;
				++s;
				--t;
			}
			n = S.length() - n + 1;
		}
		ans = Math.min(ans, solve(a, n));
		System.out.println(ans);
	}

	int solve(boolean[] b, int n) {
		int ret = Integer.MAX_VALUE / 3;
		for (int j = 0; j < b.length - 1; ++j) {
			int cur = 0;
			boolean[] a = Arrays.copyOf(b, b.length);
			for (int k = j; k < b.length - 1; ++k) {
				a[k] = !a[k];
				++cur;
			}
			int t = a.length - 1;
			int s = 0;
			while (a[t])
				--t;
			while (a[s])
				++s;
			for (int i = n - 2; i >= s; --i) {
				a[i] = !a[i];
				++cur;
			}
			for (int i = s + 1; i <= t; ++i) {
				a[i] = !a[i];
				++cur;
			}
			ArrayDeque<Integer> dq = new ArrayDeque<>();
			for (int i = s; i <= t; ++i) {
				if (!a[i])
					dq.addLast(i);
			}
			while (!dq.isEmpty()) {
				if (dq.size() >= 2) {
					int u = dq.pollFirst();
					int v = dq.pollFirst();
					cur += (v - u) * 2;
				} else {
					cur = Integer.MAX_VALUE / 3;
					break;
				}
			}
			ret = Math.min(ret, cur);
		}
		return ret;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}

}
0