結果
問題 | No.2207 pCr検査 |
ユーザー |
👑 |
提出日時 | 2023-02-03 21:27:33 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 1,238 ms / 3,000 ms |
コード長 | 4,268 bytes |
コンパイル時間 | 859 ms |
コンパイル使用メモリ | 121,724 KB |
実行使用メモリ | 86,004 KB |
最終ジャッジ日時 | 2024-06-22 17:23:18 |
合計ジャッジ時間 | 23,264 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
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)); }struct ModLong(ulong M_) {import std.conv : to;alias M = M_;enum INV_M = 1.0L / M;ulong x;this(ModLong a) { x = a.x; }this(uint x_) { x = x_ % M; }this(ulong x_) { x = cast(ulong)(x_ % M); }this(int x_) { x = ((x_ %= cast(long)(M)) < 0) ? (x_ + cast(long)(M)) : x_; }this(long x_) { x = cast(ulong)(((x_ %= cast(long)(M)) < 0) ? (x_ + cast(long)(M)) : x_); }ref ModLong opAssign(T)(inout(T) a) if (is(T == uint) || is(T == ulong) || is(T == int) || is(T == long)) { return this = ModLong(a); }ref ModLong opOpAssign(string op, T)(T a) {static if (is(T == ModLong)) {static if (op == "+") { x = ((x += a.x) >= M) ? (x - M) : x; }else static if (op == "-") { x = ((x -= a.x) >= M) ? (x + M) : x; }else static if (op == "*") {// https://github.com/kth-competitive-programming/kactl/blob/main/doc/modmul-proof.pdf// This works at least for M < 2^62, assuming the usual >= 80-bit real.const long y = x * a.x - M * cast(ulong)(INV_M * x * a.x);x = (y < 0) ? (y + M) : (y >= cast(long)(M)) ? (y - M) : y;}else static if (op == "/") { this *= a.inv(); }else static assert(false);return this;} else static if (op == "^^") {if (a < 0) return this = inv()^^(-a);ModLong b = this, c = 1U;for (long e = a; e; e >>= 1) { if (e & 1) c *= b; b *= b; }return this = c;} else {return mixin("this " ~ op ~ "= ModLong(a)");}}ModLong inv() const {ulong a = M, b = x; long y = 0, z = 1;for (; b; ) { const q = a / b; const c = a - q * b; a = b; b = c; const w = y - cast(long)(q) * z; y = z; z = w; }assert(a == 1); return ModLong(y);}ModLong opUnary(string op)() const {static if (op == "+") { return this; }else static if (op == "-") { ModLong a; a.x = x ? (M - x) : 0U; return a; }else static assert(false);}ModLong opBinary(string op, T)(T a) const { return mixin("ModLong(this) " ~ op ~ "= a"); }ModLong opBinaryRight(string op, T)(T a) const { return mixin("ModLong(a) " ~ op ~ "= this"); }bool opCast(T: bool)() const { return (x != 0U); }string toString() const { return x.to!string; }}enum MO = 1234567890123456817L;alias Mint = ModLong!MO;int K;int[] P, E;bool solve() {if (E[K - 1] != 1) {return false;}const N = P[K - 1];Mint tar = 1;foreach (k; 0 .. K) {tar *= Mint(P[k])^^E[k];}auto inv = new Mint[N + 1];inv[1] = 1;foreach (i; 2 .. N + 1) {inv[i] = -((Mint.M / i) * inv[cast(size_t)(Mint.M % i)]);}Mint bn = 1;for (int i = 0; ; ++i) {if (bn == tar) {writeln(N, " ", i);return true;}if (i == N) break;bn *= (N - i);bn *= inv[1 + i];}return false;}void main() {try {for (; ; ) {K = readInt;P = new int[K];E = new int[K];foreach (k; 0 .. K) {P[k] = readInt;E[k] = readInt;}const res = solve();if (!res) {writeln("-1 -1");}}} catch (EOFException e) {}}