結果

問題 No.5014 セクスタプル (reactive)
ユーザー ks2mks2m
提出日時 2022-12-29 20:39:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,914 ms / 2,000 ms
コード長 4,806 bytes
コンパイル時間 2,180 ms
実行使用メモリ 75,624 KB
スコア 457,852,361
平均クエリ数 35.00
最終ジャッジ日時 2022-12-29 20:43:08
合計ジャッジ時間 199,021 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,895 ms
72,068 KB
testcase_01 AC 1,897 ms
72,180 KB
testcase_02 AC 1,896 ms
71,508 KB
testcase_03 AC 1,898 ms
71,812 KB
testcase_04 AC 1,895 ms
72,428 KB
testcase_05 AC 1,898 ms
60,348 KB
testcase_06 AC 1,896 ms
60,848 KB
testcase_07 AC 1,899 ms
71,976 KB
testcase_08 AC 1,898 ms
71,644 KB
testcase_09 AC 1,897 ms
71,640 KB
testcase_10 AC 1,900 ms
71,792 KB
testcase_11 AC 1,897 ms
71,788 KB
testcase_12 AC 1,897 ms
72,752 KB
testcase_13 AC 1,897 ms
60,688 KB
testcase_14 AC 1,898 ms
71,780 KB
testcase_15 AC 1,897 ms
72,216 KB
testcase_16 AC 1,899 ms
71,684 KB
testcase_17 AC 1,895 ms
71,980 KB
testcase_18 AC 1,898 ms
71,696 KB
testcase_19 AC 1,898 ms
71,896 KB
testcase_20 AC 1,897 ms
71,916 KB
testcase_21 AC 1,897 ms
72,020 KB
testcase_22 AC 1,895 ms
71,976 KB
testcase_23 AC 1,898 ms
71,700 KB
testcase_24 AC 1,896 ms
72,688 KB
testcase_25 AC 1,899 ms
72,268 KB
testcase_26 AC 1,897 ms
72,080 KB
testcase_27 AC 1,899 ms
72,344 KB
testcase_28 AC 1,899 ms
60,816 KB
testcase_29 AC 1,899 ms
72,228 KB
testcase_30 AC 1,899 ms
72,724 KB
testcase_31 AC 1,897 ms
72,236 KB
testcase_32 AC 1,900 ms
71,884 KB
testcase_33 AC 1,902 ms
72,456 KB
testcase_34 AC 1,898 ms
71,956 KB
testcase_35 AC 1,900 ms
62,760 KB
testcase_36 AC 1,899 ms
71,952 KB
testcase_37 AC 1,895 ms
71,988 KB
testcase_38 AC 1,898 ms
63,096 KB
testcase_39 AC 1,898 ms
72,152 KB
testcase_40 AC 1,897 ms
71,728 KB
testcase_41 AC 1,899 ms
72,056 KB
testcase_42 AC 1,900 ms
71,720 KB
testcase_43 AC 1,897 ms
72,072 KB
testcase_44 AC 1,901 ms
71,784 KB
testcase_45 AC 1,898 ms
71,720 KB
testcase_46 AC 1,900 ms
72,356 KB
testcase_47 AC 1,896 ms
60,800 KB
testcase_48 AC 1,896 ms
72,368 KB
testcase_49 AC 1,897 ms
71,724 KB
testcase_50 AC 1,900 ms
72,528 KB
testcase_51 AC 1,896 ms
60,228 KB
testcase_52 AC 1,897 ms
71,868 KB
testcase_53 AC 1,898 ms
60,864 KB
testcase_54 AC 1,899 ms
71,680 KB
testcase_55 AC 1,900 ms
71,880 KB
testcase_56 AC 1,896 ms
72,392 KB
testcase_57 AC 1,897 ms
71,708 KB
testcase_58 AC 1,899 ms
71,968 KB
testcase_59 AC 1,900 ms
72,276 KB
testcase_60 AC 1,900 ms
72,012 KB
testcase_61 AC 1,898 ms
74,180 KB
testcase_62 AC 1,900 ms
74,216 KB
testcase_63 AC 1,899 ms
72,680 KB
testcase_64 AC 1,898 ms
72,124 KB
testcase_65 AC 1,902 ms
74,216 KB
testcase_66 AC 1,893 ms
74,584 KB
testcase_67 AC 1,896 ms
60,744 KB
testcase_68 AC 1,898 ms
71,996 KB
testcase_69 AC 1,897 ms
72,160 KB
testcase_70 AC 1,897 ms
73,160 KB
testcase_71 AC 1,895 ms
74,208 KB
testcase_72 AC 1,899 ms
72,848 KB
testcase_73 AC 1,898 ms
74,072 KB
testcase_74 AC 1,897 ms
71,964 KB
testcase_75 AC 1,898 ms
74,136 KB
testcase_76 AC 1,899 ms
71,976 KB
testcase_77 AC 1,895 ms
73,512 KB
testcase_78 AC 1,898 ms
60,980 KB
testcase_79 AC 1,902 ms
73,692 KB
testcase_80 AC 1,896 ms
73,648 KB
testcase_81 AC 1,897 ms
73,740 KB
testcase_82 AC 1,900 ms
73,960 KB
testcase_83 AC 1,899 ms
71,724 KB
testcase_84 AC 1,897 ms
72,192 KB
testcase_85 AC 1,900 ms
71,700 KB
testcase_86 AC 1,900 ms
74,088 KB
testcase_87 AC 1,898 ms
72,384 KB
testcase_88 AC 1,895 ms
71,676 KB
testcase_89 AC 1,899 ms
72,404 KB
testcase_90 AC 1,898 ms
60,528 KB
testcase_91 AC 1,897 ms
75,624 KB
testcase_92 AC 1,914 ms
62,300 KB
testcase_93 AC 1,899 ms
74,456 KB
testcase_94 AC 1,899 ms
72,344 KB
testcase_95 AC 1,899 ms
73,632 KB
testcase_96 AC 1,896 ms
74,268 KB
testcase_97 AC 1,897 ms
74,188 KB
testcase_98 AC 1,900 ms
73,804 KB
testcase_99 AC 1,898 ms
74,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
	static boolean debug = false;
	static long startTime;
	static int n = 6;
	static int nn = 36;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		solveOpen(br);
		solveReactive(br);
		br.close();
	}

	static void solveOpen(BufferedReader br) throws Exception {
		startTime = System.currentTimeMillis();
		List<Obj> list = new ArrayList<>(nn);
		for (int i = 0; i < nn; i++) {
			String[] sa = br.readLine().split(" ");
			Obj o = new Obj();
			for (int j = 0; j < n; j++) {
				o.d[j] = Integer.parseInt(sa[j]) - 1;
				o.cnt[o.d[j]]++;
				o.ex[o.d[j]] = true;
			}
			list.add(o);
		}
		f = new Obj[n][n];
		for (int i = 0; i < nn; i++) {
			int x = i / n;
			int y = i % n;
			f[x][y] = list.get(i);
		}
		solve1(new HashSet<>(), 1800);

		for (Obj o : list) {
			System.out.println(o.x + " " + o.y);
		}
		if (debug) {
			System.out.println(newScore);
		}
	}

	static void solveReactive(BufferedReader br) throws Exception {
		f = new Obj[n][n];
		for (int x = 0; x < n; x++) {
			for (int y = 0; y < n; y++) {
				Obj o = new Obj();
				for (int j = 0; j < n; j++) {
					o.d[j] = (int) (Math.random() * 6);
					o.cnt[o.d[j]]++;
					o.ex[o.d[j]] = true;
				}
				f[x][y] = o;
			}
		}
		startTime = System.currentTimeMillis();

		Set<Integer> fixed = new HashSet<>();
		boolean[][] done = new boolean[n][n];
		for (int t = 0; t < 35; t++) {
			Obj o = new Obj();
			label:
			for (int x = 0; x < n; x++) {
				for (int y = 0; y < n; y++) {
					if (!done[x][y]) {
						f[x][y] = o;
						break label;
					}
				}
			}
			String[] sa = br.readLine().split(" ");
			for (int j = 0; j < n; j++) {
				o.d[j] = Integer.parseInt(sa[j]) - 1;
				o.cnt[o.d[j]]++;
				o.ex[o.d[j]] = true;
			}
			solve1(fixed, 52 * (t + 1));
			System.out.println(o.x + " " + o.y);
			int x = o.x - 1;
			int y = o.y - 1;
			fixed.add(x * n + y);
			done[x][y]= true; 
		}
	}

	static void solve1(Set<Integer> fixed, long limitTime) {
		int chgNum = Math.min(3, nn - fixed.size());
		List<Integer> chgPos = new ArrayList<>(chgNum);
		bestWk = new int[chgNum];
		chgObj = new ArrayList<>(chgNum);
		while (true) {
			long time = System.currentTimeMillis() - startTime;
			if (time > limitTime) {
				break;
			}

			chgPos.clear();
			chgObj.clear();
			for (int i = 0; i < chgNum; i++) {
				int p = rand36(fixed, chgPos);
				chgPos.add(p);
				chgObj.add(f[p / n][p % n]);
			}
			newScore = 0;
			permutation(chgPos, 0, 0, new int[chgNum]);

			for (int i = 0; i < chgNum; i++) {
				int x = bestWk[i] / n;
				int y = bestWk[i] % n;
				f[x][y] = chgObj.get(i);
			}
		}

		for (int x = 0; x < n; x++) {
			for (int y = 0; y < n; y++) {
				f[x][y].x = x + 1;
				f[x][y].y = y + 1;
			}
		}
	}

	static int newScore;
	static int[] bestWk;
	static Obj[][] f;
	static List<Obj> chgObj;
	static void permutation(List<Integer> org, int used, int idx, int[] wk) {
		if (idx == org.size()) {
			for (int i = 0; i < idx; i++) {
				int x = wk[i] / n;
				int y = wk[i] % n;
				f[x][y] = chgObj.get(i);
			}
			int res = score(f);
			if (res >= newScore) {
				newScore = res;
				for (int i = 0; i < idx; i++) {
					bestWk[i] = wk[i];
				}
			}
			return;
		}

		for (int i = 0; i < org.size(); i++) {
			if ((used >> i & 1) == 0) {
				wk[idx] = org.get(i);
				permutation(org, used | 1 << i, idx + 1, wk);
			}
		}
	}

	static int rand36(Set<Integer> ng, List<Integer> ng2) {
		int rem = 36 - ng.size() - ng2.size();
		int val = (int) (Math.random() * rem) + 1;
		int cnt = 0;
		for (int i = 0; i < 36; i++) {
			if (!ng.contains(i) && !ng2.contains(i)) {
				cnt++;
				if (cnt == val) {
					return i;
				}
			}
		}
		throw new RuntimeException();
	}

	static int score(Obj[][] f) {
		int ret = 0;
		List<Obj> list = new ArrayList<>(n);
		for (int x = 0; x < n; x++) {
			for (int y = 0; y < n; y++) {
				list.add(f[x][y]);
			}
			ret += lineScore(list);
			list.clear();
		}
		for (int y = 0; y < n; y++) {
			for (int x = 0; x < n; x++) {
				list.add(f[x][y]);
			}
			ret += lineScore(list);
			list.clear();
		}
		return ret;
	}

	static int lineScore(List<Obj> list) {
		boolean[] ex = new boolean[n];
		Arrays.fill(ex, true);
		int[] cnt = new int[n];
		for (Obj o : list) {
			for (int i = 0; i < n; i++) {
				ex[i] = ex[i] && o.ex[i];
				cnt[i] += o.cnt[i];
			}
		}
		int ret = 0;
		for (int i = 0; i < n; i++) {
			if (ex[i]) {
				ret += cnt[i] - 3;
			}
		}
		return ret;
	}

	static class Obj {
		int x, y;
		int[] d = new int[n];
		int[] cnt = new int[n];
		boolean[] ex = new boolean[n];
	}
}
0