結果
問題 | No.1561 connect x connect |
ユーザー | uwi |
提出日時 | 2020-11-25 02:42:43 |
言語 | Java21 (openjdk 21) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,804 bytes |
コンパイル時間 | 4,764 ms |
コンパイル使用メモリ | 80,768 KB |
実行使用メモリ | 59,224 KB |
最終ジャッジ日時 | 2024-06-25 07:55:50 |
合計ジャッジ時間 | 15,417 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
41,124 KB |
testcase_01 | AC | 149 ms
42,384 KB |
testcase_02 | AC | 498 ms
57,176 KB |
testcase_03 | AC | 112 ms
39,880 KB |
testcase_04 | AC | 127 ms
41,252 KB |
testcase_05 | AC | 135 ms
41,504 KB |
testcase_06 | AC | 132 ms
41,332 KB |
testcase_07 | AC | 138 ms
41,840 KB |
testcase_08 | AC | 144 ms
42,016 KB |
testcase_09 | AC | 163 ms
42,816 KB |
testcase_10 | AC | 170 ms
43,696 KB |
testcase_11 | AC | 200 ms
47,020 KB |
testcase_12 | AC | 256 ms
49,780 KB |
testcase_13 | AC | 438 ms
55,772 KB |
testcase_14 | AC | 450 ms
56,344 KB |
testcase_15 | AC | 1,088 ms
59,224 KB |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | AC | 298 ms
50,932 KB |
testcase_32 | AC | 544 ms
57,340 KB |
testcase_33 | AC | 1,028 ms
59,116 KB |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
ソースコード
import java.io.PrintWriter; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class P5518_2 { static Scanner in; static PrintWriter out; static String INPUT = ""; static final int mod = 1000000007; static void solve() { int n = ni(), m = ni(); if(!(1 <= n && n <= 9))throw new IllegalArgumentException("n"); if(!(1 <= m && m <= 100))throw new IllegalArgumentException("m"); if(!(n <= m))throw new IllegalArgumentException("n<=m"); int[] a = new int[n]; Arrays.fill(a, -1); State ini = new State(a, 1L, 0); Map<Long, State> dp = new HashMap<>(); dp.put(ini.h(), ini); // 7654 // 3210N for(int j = 0;j < m+1;j++){ for(int i = 0;i < n;i++){ Map<Long, State> ndp = new HashMap<>(); for(State s : dp.values()){ // 黒いセルを追加 { int[] nclus = new int[n]; for(int k = 0;k < n-1;k++)nclus[k+1] = s.clus[k]; nclus[0] = n; if(i > 0 && s.clus[0] != -1){ for(int k = 1;k < n;k++)if(nclus[k] == s.clus[0])nclus[k] = n; } if(s.clus[n-1] != -1){ for(int k = 1;k < n;k++)if(nclus[k] == s.clus[n-1])nclus[k] = n; } normalize(nclus); int numclus = s.hidden; int x = 0; for(int v : nclus)if(v != -1)x = 1; numclus += x; if(numclus <= 1) { State ns = new State(nclus, s.val, s.hidden); add(ns, ndp); } } // 白いセルを追加 { int[] nclus = new int[n]; for(int k = 0;k < n-1;k++)nclus[k+1] = s.clus[k]; nclus[0] = -1; int nhidden = s.hidden; if(s.clus[n-1] != -1) { nhidden++; for (int k = 0; k < n - 1; k++) { if (s.clus[k] == s.clus[n - 1]) { nhidden--; break; } } } int numclus = nhidden; int x = 0; for(int v : nclus)if(v != -1)x = 1; numclus += x; if(numclus <= 1) { normalize(nclus); State ns = new State(nclus, s.val, nhidden); add(ns, ndp); } } } dp = ndp; } } long ans = 0; outer: for(State s : dp.values()){ if(s.hidden != 1)continue; for(int i = 0;i < n;i++){ if(s.clus[i] != -1)continue outer; } ans += s.val; } out.println(ans%mod); } static int[] normalize(int[] a) { int[] label = new int[11]; Arrays.fill(label, -1); int p = 0; for(int i = 0;i < a.length;i++){ if(a[i] == -1)continue; if(label[a[i]] == -1)label[a[i]] = p++; a[i] = label[a[i]]; } return a; } static void add(State s, Map<Long, State> dp) { // dp.merge(s.h(), s, (x, y) -> { // y.val += x.val; // if(y.val >= mod)y.val -= mod; // return y; // }); long key = s.h(); if(dp.containsKey(key)){ State tar = dp.get(key); tar.val += s.val; tar.val %= mod; }else{ dp.put(key, s); } } static class State { int[] clus; long val; int hidden; // clusに現れないが、すでに現れた連結成分の個数 long h() { long h = 0; for(int v : clus){ h = h * 1000000009 + v; } h = h * 1000000009 + hidden; return h; } public State(int[] clus, long val, int hidden) { this.clus = clus; this.val = val; this.hidden = hidden; } } public static void main(String[] args) throws Exception { in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT); out = new PrintWriter(System.out); long S = System.currentTimeMillis(); solve(); out.flush(); long G = System.currentTimeMillis(); tr(G-S); } static int ni() { return Integer.parseInt(in.next()); } static long nl() { return Long.parseLong(in.next()); } static double nd() { return Double.parseDouble(in.next()); } static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); } }