結果
| 問題 |
No.982 Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-11 15:50:20 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 1,105 bytes |
| コンパイル時間 | 694 ms |
| コンパイル使用メモリ | 105,024 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-22 05:04:33 |
| 合計ジャッジ時間 | 1,496 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
void main() {
auto AB = readln.split.to!(ulong[]);
auto A = AB[0];
auto B = AB[1];
long solve() {
if (A == 1 || B == 1) return 0;
if (A % 2 == 0 && B % 2 == 0) return -1;
bool[ulong] stock;
auto smaller = A < B ? A : B;
auto larger = A < B ? B : A;
auto step = larger - smaller;
foreach(n; 1..101) {
foreach(i; iota(smaller*n, larger*n+1, step)) {
stock[i] = true;
}
int continuas;
foreach(i; smaller*(n-1)..larger*n) {
if (!(i in stock)) {
continuas = 0;
continue;
}
if (++continuas == smaller) {
int answer;
foreach(j; 1..i) if (!(j in stock)) answer++;
return answer;
}
}
}
return -1;
}
solve().writeln;
}