結果

問題 No.982 Add
ユーザー allegrogikenallegrogiken
提出日時 2020-02-11 15:50:20
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 94,044 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 05:38:48
合計ジャッジ時間 1,636 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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;
}
0