結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,384 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;
    M *= m[i] / xyg[2];
    res = (res % M + M) % M;
  }
  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 = gcd(y[0], y[1]);
    auto l = y[0] * y[1] / g;
    g = gcd(l, y[2]);
    writeln(l * y[2] / g);
    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