結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2018-11-19 18:59:34 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,115 bytes |
| コンパイル時間 | 721 ms |
| コンパイル使用メモリ | 105,216 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-13 01:55:44 |
| 合計ジャッジ時間 | 1,688 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 WA * 1 |
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`
ソースコード
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));
}
ikd