結果
問題 | No.753 最強王者決定戦 |
ユーザー | 37zigen |
提出日時 | 2020-05-11 18:15:49 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 871 ms / 1,000 ms |
コード長 | 3,618 bytes |
コンパイル時間 | 2,416 ms |
コンパイル使用メモリ | 79,240 KB |
実行使用メモリ | 51,800 KB |
最終ジャッジ日時 | 2024-07-18 15:58:08 |
合計ジャッジ時間 | 6,639 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 782 ms
51,312 KB |
testcase_01 | AC | 871 ms
51,324 KB |
testcase_02 | AC | 684 ms
51,660 KB |
testcase_03 | AC | 706 ms
51,800 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { new Main().run(); } boolean[][] win; long[] cnt = new long[16]; void run() { Scanner sc = new Scanner(); win = new boolean[16][16]; for (int i = 0; i < win.length; ++i) { for (int j = 0; j < win[i].length; ++j) { win[i][j] = (sc.nextInt() == 1); } } for (int i = 0; i < win.length; ++i) { for (int j = 0; j < win[i].length; ++j) { if (i > j) { win[i][j] = !win[j][i]; } } } long[][] dp = new long[16][1 << 16]; ArrayList<Integer>[] list = new ArrayList[16]; for (int i = 0; i < 5; ++i) { list[i] = new ArrayList<Integer>(); } boolean[] add = new boolean[1 << 16]; for (int i = 0; i < 16; ++i) { dp[i][1 << i] = 1; list[0].add(1 << i); add[1 << i] = true; } for (int i = 0; i < 4; ++i) { for (int j = 0; j < list[i].size(); ++j) { for (int k = j + 1; k < list[i].size(); ++k) { int s1 = list[i].get(j); int s2 = list[i].get(k); if ((s1 & s2) > 0) { continue; } for (int a = 0; a < 16; ++a) { if (((1 << a) & s1) == 0) continue; for (int b = 0; b < 16; ++b) { if (((1 << b) & s2) == 0) continue; int whowin = win[a][b] ? a : b; dp[whowin][s1 | s2] = dp[whowin][s1 | s2] + dp[a][s1] * dp[b][s2]; if (!add[s1 | s2]) { list[i + 1].add(s1 | s2); add[s1 | s2] = true; } } } } } } PrintWriter pw=new PrintWriter(System.out); for (int i = 0; i < 16; ++i) { pw.println(dp[i][(1 << 16) - 1] * (1 << 15)); } pw.close(); } static long gcd(long a, long b) { return a==0?b:gcd(b%a,a); } static class Scanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } private void skipUnprintable() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; } public boolean hasNext() { skipUnprintable(); return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { return (int) nextLong(); } } public static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }