結果
問題 | No.5013 セクスタプル (open) |
ユーザー |
![]() |
提出日時 | 2022-12-29 17:26:31 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,903 ms / 2,000 ms |
コード長 | 3,333 bytes |
コンパイル時間 | 1,994 ms |
実行使用メモリ | 60,052 KB |
スコア | 17,101 |
最終ジャッジ日時 | 2022-12-29 17:29:51 |
合計ジャッジ時間 | 198,328 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.Arrays;import java.util.List;public class Main {static int n = 6;static int nn = 36;public static void main(String[] args) throws Exception {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));solve1(br);br.close();}static void solve1(BufferedReader br) throws Exception {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);}int chgNum = 4;List<Integer> chgPos = new ArrayList<>(chgNum);bestWk = new int[chgNum];chgObj = new ArrayList<>(chgNum);long limitTime = 1800;long startTime = System.currentTimeMillis();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();while (chgPos.contains(p)) {p = rand36();}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;}}for (Obj o : list) {System.out.println(o.x + " " + o.y);}System.out.println(newScore);}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() {return (int) (Math.random() * 36);}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];}}