結果
問題 | No.941 商とあまり |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-12-04 04:59:06 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 123 ms / 2,000 ms |
コード長 | 4,523 bytes |
コンパイル時間 | 1,298 ms |
コンパイル使用メモリ | 145,204 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 03:22:29 |
合計ジャッジ時間 | 11,554 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 3 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 109 ms
6,940 KB |
testcase_05 | AC | 108 ms
6,940 KB |
testcase_06 | AC | 113 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,944 KB |
testcase_13 | AC | 112 ms
6,944 KB |
testcase_14 | AC | 3 ms
6,940 KB |
testcase_15 | AC | 3 ms
6,944 KB |
testcase_16 | AC | 3 ms
6,940 KB |
testcase_17 | AC | 109 ms
6,940 KB |
testcase_18 | AC | 107 ms
6,940 KB |
testcase_19 | AC | 111 ms
6,940 KB |
testcase_20 | AC | 109 ms
6,944 KB |
testcase_21 | AC | 108 ms
6,940 KB |
testcase_22 | AC | 110 ms
6,940 KB |
testcase_23 | AC | 1 ms
6,940 KB |
testcase_24 | AC | 1 ms
6,944 KB |
testcase_25 | AC | 1 ms
6,940 KB |
testcase_26 | AC | 3 ms
6,944 KB |
testcase_27 | AC | 3 ms
6,944 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 3 ms
6,944 KB |
testcase_30 | AC | 3 ms
6,940 KB |
testcase_31 | AC | 3 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 112 ms
6,944 KB |
testcase_34 | AC | 110 ms
6,940 KB |
testcase_35 | AC | 108 ms
6,944 KB |
testcase_36 | AC | 3 ms
6,940 KB |
testcase_37 | AC | 6 ms
6,944 KB |
testcase_38 | AC | 33 ms
6,940 KB |
testcase_39 | AC | 111 ms
6,944 KB |
testcase_40 | AC | 109 ms
6,940 KB |
testcase_41 | AC | 110 ms
6,944 KB |
testcase_42 | AC | 109 ms
6,940 KB |
testcase_43 | AC | 13 ms
6,944 KB |
testcase_44 | AC | 40 ms
6,940 KB |
testcase_45 | AC | 44 ms
6,940 KB |
testcase_46 | AC | 22 ms
6,940 KB |
testcase_47 | AC | 2 ms
6,940 KB |
testcase_48 | AC | 108 ms
6,940 KB |
testcase_49 | AC | 2 ms
6,940 KB |
testcase_50 | AC | 12 ms
6,940 KB |
testcase_51 | AC | 7 ms
6,944 KB |
testcase_52 | AC | 30 ms
6,940 KB |
testcase_53 | AC | 6 ms
6,940 KB |
testcase_54 | AC | 27 ms
6,944 KB |
testcase_55 | AC | 46 ms
6,940 KB |
testcase_56 | AC | 12 ms
6,940 KB |
testcase_57 | AC | 109 ms
6,940 KB |
testcase_58 | AC | 109 ms
6,940 KB |
testcase_59 | AC | 2 ms
6,940 KB |
testcase_60 | AC | 2 ms
6,940 KB |
testcase_61 | AC | 2 ms
6,940 KB |
testcase_62 | AC | 110 ms
6,940 KB |
testcase_63 | AC | 117 ms
6,940 KB |
testcase_64 | AC | 108 ms
6,940 KB |
testcase_65 | AC | 108 ms
6,944 KB |
testcase_66 | AC | 2 ms
6,944 KB |
testcase_67 | AC | 110 ms
6,944 KB |
testcase_68 | AC | 3 ms
6,944 KB |
testcase_69 | AC | 115 ms
6,944 KB |
testcase_70 | AC | 112 ms
6,940 KB |
testcase_71 | AC | 3 ms
6,944 KB |
testcase_72 | AC | 3 ms
6,944 KB |
testcase_73 | AC | 108 ms
6,940 KB |
testcase_74 | AC | 110 ms
6,940 KB |
testcase_75 | AC | 108 ms
6,940 KB |
testcase_76 | AC | 108 ms
6,944 KB |
testcase_77 | AC | 108 ms
6,940 KB |
testcase_78 | AC | 117 ms
6,940 KB |
testcase_79 | AC | 111 ms
6,944 KB |
testcase_80 | AC | 108 ms
6,940 KB |
testcase_81 | AC | 111 ms
6,940 KB |
testcase_82 | AC | 114 ms
6,940 KB |
testcase_83 | AC | 111 ms
6,940 KB |
testcase_84 | AC | 108 ms
6,940 KB |
testcase_85 | AC | 108 ms
6,940 KB |
testcase_86 | AC | 112 ms
6,944 KB |
testcase_87 | AC | 111 ms
6,940 KB |
testcase_88 | AC | 108 ms
6,944 KB |
testcase_89 | AC | 109 ms
6,944 KB |
testcase_90 | AC | 109 ms
6,944 KB |
testcase_91 | AC | 109 ms
6,944 KB |
testcase_92 | AC | 110 ms
6,944 KB |
testcase_93 | AC | 111 ms
6,940 KB |
testcase_94 | AC | 109 ms
6,944 KB |
testcase_95 | AC | 111 ms
6,940 KB |
testcase_96 | AC | 111 ms
6,940 KB |
testcase_97 | AC | 109 ms
6,944 KB |
testcase_98 | AC | 108 ms
6,944 KB |
testcase_99 | AC | 108 ms
6,944 KB |
testcase_100 | AC | 109 ms
6,944 KB |
testcase_101 | AC | 110 ms
6,940 KB |
testcase_102 | AC | 123 ms
6,940 KB |
testcase_103 | AC | 110 ms
6,940 KB |
testcase_104 | AC | 1 ms
6,944 KB |
testcase_105 | AC | 1 ms
6,944 KB |
testcase_106 | AC | 1 ms
6,940 KB |
testcase_107 | AC | 1 ms
6,940 KB |
testcase_108 | AC | 1 ms
6,944 KB |
testcase_109 | AC | 1 ms
6,944 KB |
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!uint.gcdImpl`
ソースコード
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)); } enum INF = 10^^9; void main() { try { for (; ; ) { const N = readInt(); const X = readInt(); auto A = new int[N]; foreach (i; 0 .. N) { A[i] = readInt(); } A.sort; long prod = 1; foreach (i; 0 .. N) { prod *= (A[i] + 1); if (prod - 1 > X) { foreach (x; 1 .. X + 1) { write(0); } writeln(); goto failed; } } if (N >= 2 && A[0] == 1) { const lb = cast(int)(prod - 1); foreach (x; 1 .. lb) { write(0); } foreach (x; lb .. X + 1) { write(1); } writeln(); goto failed; } { auto bad = new bool[1 << N]; auto ms = new int[1 << N]; auto dp = new int[][1 << N]; foreach (u; 0 .. 1 << N) { foreach (i; 0 .. N) { if (!(u & 1 << i)) { foreach (j; i + 1 .. N) { if ((u & 1 << j) && A[i] == A[j]) { bad[u] = true; } } } } ms[u] = 1; foreach (i; 0 .. N) { if (u & 1 << i) { ms[u] = ms[u] / gcd(ms[u], A[i]) * A[i]; } } dp[u] = new int[ms[u]]; dp[u][] = INF; if (!(u & u - 1)) { chmin(dp[u][0], ms[u]); } } foreach (u; 1 .. 1 << N) { if (bad[u]) { continue; } foreach (i; 0 .. N) { if (!(u & 1 << i)) { const v = u | 1 << i; if (bad[v]) { continue; } alias Entry = Tuple!(int, "c", int, "s"); BinaryHeap!(Array!Entry, "a > b") que; auto costs = new int[ms[v]]; costs[] = INF; foreach (r; 0 .. ms[u]) { if (dp[u][r] < INF) { const z = (dp[u][r] + 1) * (A[i] + 1) - 1; const s = z % ms[v]; if (chmin(costs[s], z)) { que.insert(Entry(z, s)); } } } for (; !que.empty; ) { const c = que.front.c; const s = que.front.s; que.removeFront; if (costs[s] == c) { foreach (d; (u & u - 1) ? [ms[u] * (A[i] + 1), A[i]] : [A[i]]) { const ss = (s + d) % ms[v]; if (chmin(costs[ss], c + d)) { que.insert(Entry(c + d, ss)); } } } } foreach (s; 0 .. ms[v]) { chmin(dp[v][s], costs[s]); } } } debug { writeln(u, " ", ms[u], " ", dp[u]); } } auto ans = new char[X + 1]; ans[] = '0'; foreach (r; 0 .. ms[$ - 1]) { if (dp[$ - 1][r] < INF) { for (int x = dp[$ - 1][r]; x <= X; ) { ans[x] = '1'; if (N == 1) { break; } x += ms[$ - 1]; } } } writeln(ans[1 .. $]); } failed: } } catch (EOFException e) { } }