結果
問題 | No.936 Are |
ユーザー | uwi |
提出日時 | 2019-11-30 17:11:06 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 9,353 bytes |
コンパイル時間 | 4,628 ms |
コンパイル使用メモリ | 88,228 KB |
実行使用メモリ | 73,428 KB |
最終ジャッジ日時 | 2024-11-21 01:25:11 |
合計ジャッジ時間 | 41,025 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
ソースコード
package contest191129; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; // 指スマってきいたんだけどこのゲーム(いろんな名前があるらしい) // サンプル1が合わない。最短9ターンなのはそうだけど public class E2 { InputStream is; PrintWriter out; String INPUT = "1 20000\r\n" + "1 2 2 1\r\n" + ""; boolean win(int j, int k, int l, int m) { if(j + k == 0)return false; if(j > 0 && l > 0 && m == 0 && j+l == 5)return true; if(j > 0 && m > 0 && l == 0 && j+m == 5)return true; if(k > 0 && l > 0 && m == 0 && k+l == 5)return true; if(k > 0 && m > 0 && l == 0 && k+m == 5)return true; return false; } void solve() { int n = ni(), K = ni(); long[][][][] dp = new long[5][5][5][5]; int[] a = na(4); boolean[][][][] win = new boolean[5][5][5][5]; for(int i = 0;i < 5;i++) { for(int j = 0;j < 5;j++) { for(int k = 0;k < 5;k++) { for(int l = 0;l < 5;l++) { win[i][j][k][l] = win(i, j, k, l); } } } } int[][][][][][] nexsh = new int[5][5][5][5][][]; int[][][][][][] nexsi = new int[5][5][5][5][][]; for(int j = 0;j < 5;j++) { for(int k = 0;k < 5;k++) { for(int l = 0;l < 5;l++) { for(int m = 0;m < 5;m++) { if(j + k == 0)continue; if(l + m == 0)continue; if(win[j][k][l][m])continue; // 必勝ならおわり nexsh[j][k][l][m] = new int[15][]; int p = 0; boolean allose = true; if(j > 0 && l > 0){ int nl = (j+l)%5; if(!win[nl][m][j][k]) { allose = false; nexsh[j][k][l][m][p++] = new int[] {nl, m, j, k}; } } if(j > 0 && m > 0){ int nm = (j+m)%5; if(!win[l][nm][j][k]) { allose = false; nexsh[j][k][l][m][p++] = new int[] {l, nm, j, k}; } } if(k > 0 && l > 0){ int nl = (k+l)%5; if(!win[nl][m][j][k]) { allose = false; nexsh[j][k][l][m][p++] = new int[] {nl, m, j, k}; } } if(k > 0 && m > 0){ int nm = (k+m)%5; if(!win[l][nm][j][k]) { allose = false; nexsh[j][k][l][m][p++] = new int[] {l, nm, j, k}; } } { int s = j+k; for(int t = 0;t <= s;t++) { if(t == j || t == k)continue; if(t >= 5 || s-t >= 5)continue; if(!win(l, m, t, s-t)) { allose = false; nexsh[j][k][l][m][p++] = new int[] {l, m, t, s-t}; } } s -= 5; if(s > 0) { // 自滅はしない for(int t = 0;t <= s;t++) { if(!win(l, m, t, s-t)) { allose = false; nexsh[j][k][l][m][p++] = new int[] {l, m, t, s-t}; } } } } if(allose) { // 必敗なら取れる手すべてを適当にとる // tr(j, k, l, m, dp[j][k][l][m]); if(j > 0 && l > 0){ int nl = (j+l)%5; nexsh[j][k][l][m][p++] = new int[] {nl, m, j, k}; } if(j > 0 && m > 0){ int nm = (j+m)%5; nexsh[j][k][l][m][p++] = new int[] {l, nm, j, k}; } if(k > 0 && l > 0){ int nl = (k+l)%5; nexsh[j][k][l][m][p++] = new int[] {nl, m, j, k}; } if(k > 0 && m > 0){ int nm = (k+m)%5; nexsh[j][k][l][m][p++] = new int[] {l, nm, j, k}; } { int s = j+k; for(int t = 0;t <= s;t++) { if(t == j || t == k)continue; if(t >= 5 || s-t >= 5)continue; nexsh[j][k][l][m][p++] = new int[] {l, m, t, s-t}; } s -= 5; if(s > 0) { for(int t = 0;t <= s;t++) { nexsh[j][k][l][m][p++] = new int[] {l, m, t, s-t}; } } } } nexsh[j][k][l][m] = Arrays.copyOf(nexsh[j][k][l][m], p); // tr(j, k, l, m, nexsh[j][k][l][m]); } } } } for(int j = 0;j < 5;j++) { for(int k = 0;k < 5;k++) { for(int l = 0;l < 5;l++) { for(int m = 0;m < 5;m++) { if(j + k == 0)continue; if(l + m == 0)continue; nexsi[j][k][l][m] = new int[15][]; int p = 0; if(j > 0 && l > 0){ int nl = (j+l)%5; nexsi[j][k][l][m][p++] = new int[] {nl, m, j, k}; } if(j > 0 && m > 0){ int nm = (j+m)%5; nexsi[j][k][l][m][p++] = new int[] {l, nm, j, k}; } if(k > 0 && l > 0){ int nl = (k+l)%5; nexsi[j][k][l][m][p++] = new int[] {nl, m, j, k}; } if(k > 0 && m > 0){ int nm = (k+m)%5; nexsi[j][k][l][m][p++] = new int[] {l, nm, j, k}; } { int s = j+k; for(int t = 0;t <= s;t++) { if(t == j || t == k)continue; if(t >= 5 || s-t >= 5)continue; nexsi[j][k][l][m][p++] = new int[] {l, m, t, s-t}; } s -= 5; if(s > 0) { for(int t = 0;t <= s;t++) { nexsi[j][k][l][m][p++] = new int[] {l, m, t, s-t}; } } } nexsi[j][k][l][m] = Arrays.copyOf(nexsi[j][k][l][m], p); // if(j == 0)tr(j, k, l, m, nexsi[j][k][l][m]); } } } } if(n == 0) { dp[a[0]][a[1]][a[2]][a[3]] = 1; if(K % 2 == 0)K--; }else { dp[a[2]][a[3]][a[0]][a[1]] = 1; if(K % 2 == 1)K--; } long ans = 0; int mod = 1000000007; for(int i = 0;i <= K;i++) { for(int j = 0;j < 5;j++) { for(int k = 0;k < 5;k++) { if(((n^i)&1) == 1){ ans += dp[0][0][j][k]; } dp[0][0][j][k] = 0; } } if(i == K)break; long[][][][] ndp = new long[5][5][5][5]; if(((n^i)&1) == 1){ // hasitaka for(int j = 0;j < 5;j++) { for(int k = 0;k < 5;k++) { for(int l = 0;l < 5;l++) { for(int m = 0;m < 5;m++) { if(dp[j][k][l][m] == 0)continue; if(nexsh[j][k][l][m] == null)continue; for(int[] ne : nexsh[j][k][l][m]) { ndp[ne[0]][ne[1]][ne[2]][ne[3]] += dp[j][k][l][m]; if(ndp[ne[0]][ne[1]][ne[2]][ne[3]] >= mod)ndp[ne[0]][ne[1]][ne[2]][ne[3]] -= mod; } } } } } }else { // iot for(int j = 0;j < 5;j++) { for(int k = 0;k < 5;k++) { for(int l = 0;l < 5;l++) { for(int m = 0;m < 5;m++) { if(dp[j][k][l][m] == 0)continue; if(nexsi[j][k][l][m] == null)continue; for(int[] ne : nexsi[j][k][l][m]) { ndp[ne[0]][ne[1]][ne[2]][ne[3]] += dp[j][k][l][m]; if(ndp[ne[0]][ne[1]][ne[2]][ne[3]] >= mod)ndp[ne[0]][ne[1]][ne[2]][ne[3]] -= mod; } } } } } } dp = ndp; } out.println(ans%mod); } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); // Thread t = new Thread(null, null, "~", Runtime.getRuntime().maxMemory()){ // @Override // public void run() { // long s = System.currentTimeMillis(); // solve(); // out.flush(); // if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); // } // }; // t.start(); // t.join(); } public static void main(String[] args) throws Exception { new E2().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private long[] nal(int n) { long[] a = new long[n]; for(int i = 0;i < n;i++)a[i] = nl(); return a; } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[][] nmi(int n, int m) { int[][] map = new int[n][]; for(int i = 0;i < n;i++)map[i] = na(m); return map; } private int ni() { return (int)nl(); } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }