結果

問題 No.186 中華風 (Easy)
ユーザー te-shte-sh
提出日時 2016-09-13 16:29:47
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,011 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 168,604 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-09-02 22:05:49
合計ジャッジ時間 3,136 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,368 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,372 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 1 ms
4,372 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,372 KB
testcase_20 AC 2 ms
4,368 KB
testcase_21 AC 2 ms
4,372 KB
testcase_22 AC 2 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

T exEuclid(T)(T a, T b, ref T x, ref T y)
{
  auto g = a;
  x = 1;
  y = 0;
  if (b != 0) {
    g = exEuclid(b, a % b, y, x);
    y -= a / b * x;
  }
  return g;
}

void main()
{
  auto rd1 = readln.split.map!(a => BigInt(a));
  auto x1 = rd1[0], y1 = rd1[1];
  auto rd2 = readln.split.map!(a => BigInt(a));
  auto x2 = rd2[0], y2 = rd2[1];
  auto rd3 = readln.split.map!(a => BigInt(a));
  auto x3 = rd3[0], y3 = rd3[1];

  BigInt a, b, g, l, r;

  g = exEuclid(y1, y2, a, b);

  if (x1 % g != x2 % g) {
    writeln(-1);
    return;
  }

  l = y1 / g * y2;
  r = (y1 / g * x2 * a + y2 / g * x1 * b) % l;

  BigInt x4 = r, y4 = l;

  g = exEuclid(y3, y4, a, b);

  if (x3 % g != x4 % g) {
    writeln(-1);
    return;
  }

  l = y3 / g * y4;
  r = (y3 / g * x4 * a + y4 / g * x3 * b) % l;

  writeln(r);
}
0