結果

問題 No.2207 pCr検査
ユーザー 👑 hos.lyrichos.lyric
提出日時 2023-02-03 21:27:33
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,438 ms / 3,000 ms
コード長 4,268 bytes
コンパイル時間 1,945 ms
コンパイル使用メモリ 112,368 KB
実行使用メモリ 87,912 KB
最終ジャッジ日時 2023-09-04 19:42:47
合計ジャッジ時間 30,551 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 975 ms
82,660 KB
testcase_03 AC 554 ms
50,272 KB
testcase_04 AC 655 ms
62,800 KB
testcase_05 AC 1,034 ms
78,264 KB
testcase_06 AC 652 ms
73,608 KB
testcase_07 AC 472 ms
48,968 KB
testcase_08 AC 283 ms
29,036 KB
testcase_09 AC 796 ms
63,256 KB
testcase_10 AC 338 ms
46,372 KB
testcase_11 AC 733 ms
61,264 KB
testcase_12 AC 1,204 ms
70,680 KB
testcase_13 AC 690 ms
45,088 KB
testcase_14 AC 153 ms
14,612 KB
testcase_15 AC 1,311 ms
80,532 KB
testcase_16 AC 618 ms
39,032 KB
testcase_17 AC 1,053 ms
66,480 KB
testcase_18 AC 763 ms
51,216 KB
testcase_19 AC 400 ms
27,936 KB
testcase_20 AC 590 ms
42,580 KB
testcase_21 AC 1,438 ms
83,504 KB
testcase_22 AC 441 ms
20,580 KB
testcase_23 AC 443 ms
20,056 KB
testcase_24 AC 180 ms
18,500 KB
testcase_25 AC 590 ms
39,112 KB
testcase_26 AC 518 ms
35,144 KB
testcase_27 AC 1,009 ms
67,872 KB
testcase_28 AC 1,209 ms
86,484 KB
testcase_29 AC 1,215 ms
87,912 KB
testcase_30 AC 1,205 ms
87,640 KB
testcase_31 AC 1,229 ms
87,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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) {
  }
}
0