結果

問題 No.176 2種類の切手
ユーザー te-shte-sh
提出日時 2017-02-07 18:46:43
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,149 bytes
コンパイル時間 836 ms
コンパイル使用メモリ 105,508 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-03 01:24:22
合計ジャッジ時間 3,729 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.container; // SList, DList, BinaryHeap
import std.typecons;  // Tuple, Nullable, BigFlags
import std.math;      // math functions
import std.numeric;   // gcd
import std.bigint;    // BigInt
import std.random;    // random
import std.bitmanip;  // BitArray
import core.bitop;    // bit operation
import std.regex;     // RegEx
import std.uni;       // unicode

void main()
{
  auto rd = readln.split.to!(long[]), a = rd[0], b = rd[1], t = rd[2];

  long x, y;
  auto g = exEuclid(a, b, x, y);
  a /= g; b /= g; t = (t + g - 1) / g;

  auto calc() {
    auto miAB = min(a, b);
    auto miT = (t + miAB - 1) / miAB * miAB;
    if (x < 0) {
      foreach (k; max(t, miAB)..miT) {
        if (((k * -x) + b - 1) / b <= (k * y) / a) return k;
      }
    } else {
      foreach (k; max(t, miAB)..miT)
        if (((k * -y) + a - 1) / a <= (k * x) / b) return k;
    }
    return miT;
  }

  writeln(calc * g);
}

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