結果

問題 No.186 中華風 (Easy)
ユーザー ikdikd
提出日時 2018-11-19 18:59:34
言語 D
(dmd 2.105.2)
結果
WA  
実行時間 -
コード長 1,115 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 93,744 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 21:16:08
合計ジャッジ時間 1,987 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/dmd2/linux/bin64/../../src/phobos/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`

ソースコード

diff #

long[] ext_gcd(long a, long b) {
  if (b == 0) {
    return [1, 0, a];
  } else {
    auto xyg = ext_gcd(b, a % b);
    return [xyg[1], xyg[0] - a / b * xyg[1], xyg[2]];
  }
}

long chi_rem(long[] a, long[] m) {
  import std.stdio;

  assert(a.length == m.length);
  long res = 0, M = 1;
  foreach (i; 0 .. a.length) {
    auto xyg = ext_gcd(M, m[i]);
    if ((a[i] - res) % xyg[2] != 0) {
      return -1;
    }
    res += (a[i] - res) / xyg[2] * xyg[0] % (m[i] / xyg[2]) * M;
    M *= m[i] / xyg[2];
  }
  return (res % M + M) % M;
}

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.numeric;

  auto x = new long[](3), y = new long[](3);
  rd(x[0], y[0]);
  rd(x[1], y[1]);
  rd(x[2], y[2]);
  if (reduce!"a+b"(x) == 0) {
    auto g = reduce!(gcd)(y);
    writeln(reduce!((res, val) => (res * val / g))(1L, y));
    return;
  }
  writeln(chi_rem(x, y));
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}
0