結果
問題 | No.5014 セクスタプル (reactive) |
ユーザー | EvbCFfp1XB |
提出日時 | 2022-12-29 16:55:43 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 235 ms / 2,000 ms |
コード長 | 11,456 bytes |
コンパイル時間 | 2,179 ms |
実行使用メモリ | 66,572 KB |
スコア | 545,592,806 |
平均クエリ数 | 35.00 |
最終ジャッジ日時 | 2022-12-29 16:56:13 |
合計ジャッジ時間 | 27,077 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 196 ms
65,644 KB |
testcase_01 | AC | 206 ms
65,728 KB |
testcase_02 | AC | 189 ms
65,808 KB |
testcase_03 | AC | 193 ms
66,196 KB |
testcase_04 | AC | 200 ms
65,796 KB |
testcase_05 | AC | 192 ms
65,812 KB |
testcase_06 | AC | 193 ms
65,688 KB |
testcase_07 | AC | 194 ms
66,036 KB |
testcase_08 | AC | 195 ms
66,040 KB |
testcase_09 | AC | 195 ms
65,852 KB |
testcase_10 | AC | 203 ms
65,648 KB |
testcase_11 | AC | 194 ms
66,076 KB |
testcase_12 | AC | 192 ms
66,080 KB |
testcase_13 | AC | 187 ms
66,148 KB |
testcase_14 | AC | 194 ms
65,780 KB |
testcase_15 | AC | 191 ms
65,784 KB |
testcase_16 | AC | 210 ms
66,296 KB |
testcase_17 | AC | 192 ms
65,752 KB |
testcase_18 | AC | 195 ms
66,108 KB |
testcase_19 | AC | 190 ms
65,584 KB |
testcase_20 | AC | 192 ms
65,872 KB |
testcase_21 | AC | 201 ms
65,608 KB |
testcase_22 | AC | 193 ms
66,244 KB |
testcase_23 | AC | 194 ms
65,692 KB |
testcase_24 | AC | 191 ms
65,760 KB |
testcase_25 | AC | 189 ms
66,120 KB |
testcase_26 | AC | 191 ms
65,856 KB |
testcase_27 | AC | 203 ms
66,488 KB |
testcase_28 | AC | 188 ms
66,184 KB |
testcase_29 | AC | 193 ms
65,828 KB |
testcase_30 | AC | 193 ms
65,780 KB |
testcase_31 | AC | 189 ms
66,044 KB |
testcase_32 | AC | 200 ms
65,540 KB |
testcase_33 | AC | 192 ms
65,776 KB |
testcase_34 | AC | 188 ms
65,760 KB |
testcase_35 | AC | 191 ms
65,968 KB |
testcase_36 | AC | 196 ms
66,196 KB |
testcase_37 | AC | 188 ms
66,376 KB |
testcase_38 | AC | 205 ms
65,448 KB |
testcase_39 | AC | 188 ms
66,016 KB |
testcase_40 | AC | 235 ms
65,748 KB |
testcase_41 | AC | 187 ms
65,660 KB |
testcase_42 | AC | 194 ms
66,332 KB |
testcase_43 | AC | 192 ms
65,648 KB |
testcase_44 | AC | 208 ms
65,940 KB |
testcase_45 | AC | 190 ms
65,792 KB |
testcase_46 | AC | 189 ms
65,372 KB |
testcase_47 | AC | 187 ms
65,944 KB |
testcase_48 | AC | 193 ms
65,720 KB |
testcase_49 | AC | 195 ms
66,472 KB |
testcase_50 | AC | 189 ms
65,708 KB |
testcase_51 | AC | 193 ms
66,024 KB |
testcase_52 | AC | 190 ms
66,168 KB |
testcase_53 | AC | 195 ms
66,288 KB |
testcase_54 | AC | 191 ms
66,572 KB |
testcase_55 | AC | 202 ms
66,232 KB |
testcase_56 | AC | 190 ms
65,676 KB |
testcase_57 | AC | 195 ms
65,916 KB |
testcase_58 | AC | 185 ms
65,820 KB |
testcase_59 | AC | 187 ms
66,200 KB |
testcase_60 | AC | 189 ms
65,688 KB |
testcase_61 | AC | 206 ms
65,704 KB |
testcase_62 | AC | 198 ms
65,608 KB |
testcase_63 | AC | 190 ms
65,460 KB |
testcase_64 | AC | 188 ms
65,832 KB |
testcase_65 | AC | 185 ms
65,644 KB |
testcase_66 | AC | 193 ms
65,800 KB |
testcase_67 | AC | 206 ms
65,788 KB |
testcase_68 | AC | 195 ms
65,312 KB |
testcase_69 | AC | 194 ms
66,044 KB |
testcase_70 | AC | 192 ms
65,772 KB |
testcase_71 | AC | 193 ms
65,496 KB |
testcase_72 | AC | 195 ms
65,768 KB |
testcase_73 | AC | 205 ms
65,848 KB |
testcase_74 | AC | 199 ms
65,716 KB |
testcase_75 | AC | 193 ms
65,520 KB |
testcase_76 | AC | 191 ms
65,652 KB |
testcase_77 | AC | 188 ms
66,136 KB |
testcase_78 | AC | 197 ms
65,884 KB |
testcase_79 | AC | 191 ms
66,228 KB |
testcase_80 | AC | 196 ms
66,336 KB |
testcase_81 | AC | 191 ms
65,608 KB |
testcase_82 | AC | 194 ms
66,152 KB |
testcase_83 | AC | 190 ms
65,844 KB |
testcase_84 | AC | 206 ms
66,460 KB |
testcase_85 | AC | 189 ms
65,768 KB |
testcase_86 | AC | 192 ms
65,868 KB |
testcase_87 | AC | 188 ms
66,008 KB |
testcase_88 | AC | 194 ms
66,344 KB |
testcase_89 | AC | 190 ms
66,212 KB |
testcase_90 | AC | 203 ms
66,484 KB |
testcase_91 | AC | 191 ms
65,932 KB |
testcase_92 | AC | 196 ms
65,676 KB |
testcase_93 | AC | 190 ms
66,052 KB |
testcase_94 | AC | 188 ms
65,456 KB |
testcase_95 | AC | 204 ms
66,172 KB |
testcase_96 | AC | 187 ms
65,588 KB |
testcase_97 | AC | 196 ms
65,940 KB |
testcase_98 | AC | 192 ms
65,856 KB |
testcase_99 | AC | 193 ms
66,408 KB |
ソースコード
import java.util.Arrays; import java.util.Scanner; public class Main { private int[][] dice; private int[][] table; private int[] counts = new int[6]; public static void main(String[] args) throws Exception { new Main().run(); } private void run() { solve(); } private void solve() { try (final Scanner in = new Scanner(System.in)) { table = new int[6][6]; for (int r = 0; r < 6; r++) { Arrays.fill(table[r], -1); } dice = new int[35][6]; for (int index = 0; index < 35; index++) { for (int j = 0; j < 6; j++) { dice[index][j] = in.nextInt() - 1; if (index == 0 && j == 0) { Constants.watch.init(); } } int[] counts = counts(dice[index]); int best = (int) -1e9; int bestR = -1; int bestC = -1; for (int d = 0; d < 6; d++) { for (int d2 = 0; d2 < 6; d2++) { int r = dice[index][d]; int c = dice[index][d2]; if (r == c) { if (counts[r] < 3) { continue; } } int[][] copyTable = copy(table); if (copyTable[r][c] >= 0) { continue; } copyTable[r][c] = index; int score = calculateScore(copyTable); if (score > best) { best = score; bestR = r; bestC = c; } } } if (bestR < 0) { for (int r = 0; r < 6; r++) { for (int c = 0; c < 6; c++) { int[][] copyTable = copy(table); if (copyTable[r][c] >= 0) { continue; } copyTable[r][c] = index; int score = calculateScore(copyTable); if (score > best) { best = score; bestR = r; bestC = c; } } } } table[bestR][bestC] = index; Utils.debug(index, "best", best); System.out.println((bestR + 1) + " " + (bestC + 1)); System.out.flush(); } } catch (Exception e) { e.printStackTrace(); } } private int[] counts(int[] dice) { int[] counts = new int[6]; for (int i = 0; i < 6; i++) { counts[dice[i]]++; } return counts; } private int[][] copy(int[][] table) { int[][] copy = new int[6][6]; for (int r = 0; r < 6; r++) { for (int c = 0; c < 6; c++) { copy[r][c] = table[r][c]; } } return copy; } private int[] rank(int[] dice) { int[] counts = new int[6]; for (int i = 0; i < dice.length; i++) { counts[dice[i]]++; } int[] rank = new int[6]; for (int i = 0; i < counts.length; i++) { for (int j = 0; j < counts.length; j++) { if (j == i) { continue; } if (counts[i] < counts[j]) { rank[i]++; } } } return rank; } private int calculateScore(int[][] table) { int score = 0; for (int r = 0; r < 6; r++) { score += partScoreRow(table, r); } for (int c = 0; c < 6; c++) { score += partScoreColumn(table, c); } return score; } private int partScoreColumn(int[][] table, int c) { Arrays.fill(counts, 0); int mask = (1 << 6) - 1; int count_r = 0; for (int r = 0; r < 6; r++) { int index = table[r][c]; if (index < 0) { continue; } count_r++; int mask2 = 0; for (int i = 0; i < 6; i++) { counts[dice[index][i]]++; mask2 |= (1 << dice[index][i]); } mask &= mask2; } int part_score = 0; for (int i = 0; i < 6; i++) { if ((mask & (1 << i)) == 0) { continue; } if (counts[i] == 0) { continue; } part_score += 3; part_score += counts[i] - count_r; } return part_score; } private int partScoreRow(int[][] table, int r) { Arrays.fill(counts, 0); int mask = (1 << 6) - 1; int count_c = 0; for (int c = 0; c < 6; c++) { int index = table[r][c]; if (index < 0) { continue; } count_c++; int mask2 = 0; for (int i = 0; i < 6; i++) { counts[dice[index][i]]++; mask2 |= (1 << dice[index][i]); } mask &= mask2; } int part_score = 0; for (int i = 0; i < 6; i++) { if ((mask & (1 << i)) == 0) { continue; } if (counts[i] == 0) { continue; } part_score += 3; part_score += counts[i] - count_c; } return part_score; } } class SAState { public static final boolean useTime = true; public double startTime; public double endTime; public double time; public double startTemperature; public double endTemperature; public double inverseTemperature; public double lastAcceptTemperature; public double startRange; public double endRange; public double range; public int numIterations; public int validIterations; public int acceptIterations; private double[] log = new double[32768]; public SAState() { for (int i = 0; i < log.length; i++) { log[i] = Math.log((i + 0.5) / log.length); } } public void init() { numIterations = 0; validIterations = 0; acceptIterations = 0; startTime = useTime ? Constants.watch.getSecond() : numIterations; update(); lastAcceptTemperature = inverseTemperature; } public void update() { updateTime(); updateTemperature(); } public boolean useExp = !true; public void updateTemperature() { if (useExp) { double time0to1 = elapsedPercentage(startTime, endTime, time); double startY = startTemperature; double endY = endTemperature; double startX = Math.log(startY); double endX = Math.log(endY); double xStartToEnd = interpolate(startX, endX, time0to1); double temperature = Math.exp(xStartToEnd); inverseTemperature = 1.0 / temperature; } else { double time0to1 = elapsedPercentage(startTime, endTime, time); double startY = startTemperature; double endY = endTemperature; double temperature = interpolate(startY, endY, time0to1); inverseTemperature = 1.0 / temperature; } } private double elapsedPercentage(double min, double max, double v) { return (v - min) / (max - min); } private double interpolate(double v0, double v1, double d0to1) { return v0 + (v1 - v0) * d0to1; } public void updateRange() { range = endRange + (startRange - endRange) * Math.pow((endTime - time) / (endTime - startTime), 1.0); } public void updateTime() { time = useTime ? Constants.watch.getSecond() : numIterations; } public boolean isTLE() { return time >= endTime; } public boolean accept(double deltaScore) { return acceptB(deltaScore); } public boolean acceptB(double deltaScore) { validIterations++; if (deltaScore > -1e-9) { acceptIterations++; return true; } double d = deltaScore * inverseTemperature; if (d < -10) { return false; } if (log[Constants.RNG.nextInt() & 32767] < d) { acceptIterations++; lastAcceptTemperature = inverseTemperature; return true; } return false; } public boolean acceptS(double deltaScore) { validIterations++; if (deltaScore < 1e-9) { acceptIterations++; return true; } double d = -deltaScore * inverseTemperature; if (d < -10) { return false; } if (log[Constants.RNG.nextInt() & 32767] < d) { acceptIterations++; lastAcceptTemperature = inverseTemperature; return true; } return false; } } final class Utils { private Utils() { } public static final void debug(Object... o) { System.err.println(toString(o)); System.err.flush(); } public static final String toString(Object... o) { return Arrays.deepToString(o); } public static boolean isValid(int v, int min, int minUpper) { return v >= min && v < minUpper; } } class Watch { private long start; public Watch() { init(); } public double getSecond() { return (System.nanoTime() - start) * 1e-9; } public void init() { init(System.nanoTime()); } private void init(long start) { this.start = start; } public String getSecondString() { return toString(getSecond()); } public static final String toString(double second) { if (second < 60) { return String.format("%5.2fs", second); } else if (second < 60 * 60) { int minute = (int) (second / 60); return String.format("%2dm%2ds", minute, (int) (second % 60)); } else { int hour = (int) (second / (60 * 60)); int minute = (int) (second / 60); return String.format("%2dh%2dm%2ds", hour, minute % (60), (int) (second % 60)); } } } interface Constants { Watch watch = new Watch(); PCG_XSH_RR RNG = new PCG_XSH_RR(System.nanoTime()); } final class PCG_XSH_RR { private long state = 5342; public PCG_XSH_RR(final long state) { this.state = state; } public int nextInt() { final long oldstate = state; state = oldstate * 6364136223846793005L + 521L; final int xorshift = (int) (((oldstate >>> 18) ^ oldstate) >>> 27); final int rotation = (int) (oldstate >>> 59); return (xorshift >>> rotation) | (xorshift << (-rotation & 31)); } public int nextInt(int n) { return (int) (n * nextDouble()); } public double nextDouble() { return (nextInt() >>> 1) * 4.6566128730773926E-10; } }