結果
問題 | No.1711 Divide LCM |
ユーザー | 👑 hos.lyric |
提出日時 | 2022-10-27 20:58:28 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 452 ms / 4,000 ms |
コード長 | 3,869 bytes |
コンパイル時間 | 918 ms |
コンパイル使用メモリ | 123,176 KB |
実行使用メモリ | 66,536 KB |
最終ジャッジ日時 | 2024-06-22 16:30:45 |
合計ジャッジ時間 | 12,034 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 3 ms
6,944 KB |
testcase_04 | AC | 9 ms
6,940 KB |
testcase_05 | AC | 31 ms
6,944 KB |
testcase_06 | AC | 11 ms
6,940 KB |
testcase_07 | AC | 27 ms
6,944 KB |
testcase_08 | AC | 12 ms
6,940 KB |
testcase_09 | AC | 56 ms
11,864 KB |
testcase_10 | AC | 12 ms
6,944 KB |
testcase_11 | AC | 77 ms
12,104 KB |
testcase_12 | AC | 11 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 5 ms
6,944 KB |
testcase_15 | AC | 7 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 6 ms
6,940 KB |
testcase_18 | AC | 208 ms
20,588 KB |
testcase_19 | AC | 198 ms
22,148 KB |
testcase_20 | AC | 191 ms
21,584 KB |
testcase_21 | AC | 255 ms
27,608 KB |
testcase_22 | AC | 452 ms
62,496 KB |
testcase_23 | AC | 414 ms
66,536 KB |
testcase_24 | AC | 214 ms
16,316 KB |
testcase_25 | AC | 206 ms
17,232 KB |
testcase_26 | AC | 202 ms
22,848 KB |
testcase_27 | AC | 211 ms
16,308 KB |
testcase_28 | AC | 198 ms
16,024 KB |
testcase_29 | AC | 4 ms
6,944 KB |
testcase_30 | AC | 214 ms
17,540 KB |
testcase_31 | AC | 4 ms
6,944 KB |
testcase_32 | AC | 273 ms
27,812 KB |
testcase_33 | AC | 265 ms
26,684 KB |
testcase_34 | AC | 10 ms
6,940 KB |
testcase_35 | AC | 203 ms
16,588 KB |
testcase_36 | AC | 216 ms
16,276 KB |
testcase_37 | AC | 214 ms
16,652 KB |
testcase_38 | AC | 232 ms
26,940 KB |
testcase_39 | AC | 273 ms
19,160 KB |
testcase_40 | AC | 4 ms
6,940 KB |
testcase_41 | AC | 4 ms
6,940 KB |
testcase_42 | AC | 5 ms
6,940 KB |
testcase_43 | AC | 4 ms
6,940 KB |
testcase_44 | AC | 5 ms
6,944 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } void main() { try { for (; ; ) { const N = readInt; auto M = new int[N]; auto P = new int[][N]; auto E = new int[][N]; auto A = new int[N]; A[] = 1; foreach (i; 0 .. N) { M[i] = readInt; P[i] = new int[M[i]]; E[i] = new int[M[i]]; foreach (j; 0 .. M[i]) { P[i][j] = readInt; E[i][j] = readInt; A[i] *= P[i][j]^^E[i][j]; } } int maxP; foreach (i; 0 .. N) { chmax(maxP, P[i].maxElement); } auto maxEs = new int[maxP + 1]; foreach (i; 0 .. N) { foreach (j; 0 .. M[i]) { chmax(maxEs[P[i][j]], E[i][j]); } } int[] qs; foreach (q; 0 .. maxP + 1) if (maxEs[q]) { qs ~= q; } const qsLen = cast(int)(qs.length); debug { writeln("qs = ", qs); } bool bad; bool[long] app; auto prods = new int[1 << 9]; auto bs = new int[N]; foreach (i; 0 .. N) { int[] ps; foreach (j; 0 .. M[i]) if (maxEs[P[i][j]] == E[i][j]) { ps ~= P[i][j]; } const psLen = cast(int)(ps.length); if (psLen == qsLen) { bad = true; break; } assert(psLen <= 9); prods[0] = 1; foreach (j; 0 .. psLen) foreach (h; 0 .. 1 << j) { prods[h | 1 << j] = prods[h] * ps[j]; } foreach (h; 0 .. 1 << psLen) { app[prods[h]] = true; } bs[i] = prods[(1 << psLen) - 1]; } if (bad) { writeln(-1); continue; } debug { writeln("app = ", app); writeln("bs = ", bs); } int best = 10; int[] ans; int[] chosen = new int[10]; void dfs(int pos, int last, long prod) { if (best <= pos) { return; } if (prod !in app) { best = pos; ans = chosen.dup; return; } foreach (k; last + 1 .. qsLen) { chosen[pos] = qs[k]; dfs(pos + 1, k, prod * qs[k]); if (best <= pos + 1) { return; } } } dfs(0, -1, 1); ans.length = best; debug { writeln("ans = ", ans); } auto used = new bool[N]; writeln(best); foreach (q; ans) { int cnt; foreach (i; 0 .. N) if (!used[i] && bs[i] % q != 0) { ++cnt; } write(cnt); foreach (i; 0 .. N) if (!used[i] && bs[i] % q != 0) { used[i] = true; write(" ", A[i]); } writeln; } } } catch (EOFException e) { } }