結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー tnakao0123tnakao0123
提出日時 2022-10-15 02:37:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 42,004 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-09 01:59:59
合計ジャッジ時間 5,532 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 107 ms
4,380 KB
testcase_09 AC 93 ms
4,384 KB
testcase_10 AC 111 ms
4,380 KB
testcase_11 AC 111 ms
4,380 KB
testcase_12 AC 52 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 42 ms
4,380 KB
testcase_19 AC 80 ms
4,380 KB
testcase_20 AC 75 ms
4,384 KB
testcase_21 AC 34 ms
4,384 KB
testcase_22 AC 28 ms
4,380 KB
testcase_23 AC 17 ms
4,384 KB
testcase_24 AC 108 ms
4,384 KB
testcase_25 AC 16 ms
4,380 KB
testcase_26 AC 81 ms
4,380 KB
testcase_27 AC 45 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 76 ms
4,384 KB
testcase_39 AC 37 ms
4,384 KB
testcase_40 AC 37 ms
4,380 KB
testcase_41 AC 23 ms
4,380 KB
testcase_42 AC 89 ms
4,384 KB
testcase_43 AC 43 ms
4,380 KB
testcase_44 AC 87 ms
4,384 KB
testcase_45 AC 76 ms
4,380 KB
testcase_46 AC 70 ms
4,384 KB
testcase_47 AC 10 ms
4,380 KB
testcase_48 AC 2 ms
4,384 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,384 KB
testcase_52 AC 1 ms
4,380 KB
testcase_53 AC 1 ms
4,384 KB
testcase_54 AC 1 ms
4,380 KB
testcase_55 AC 80 ms
4,380 KB
testcase_56 AC 112 ms
4,380 KB
testcase_57 AC 112 ms
4,384 KB
testcase_58 AC 112 ms
4,384 KB
testcase_59 AC 112 ms
4,384 KB
testcase_60 AC 57 ms
4,380 KB
testcase_61 AC 57 ms
4,384 KB
testcase_62 AC 113 ms
4,384 KB
testcase_63 AC 112 ms
4,384 KB
testcase_64 AC 113 ms
4,384 KB
testcase_65 AC 113 ms
4,380 KB
testcase_66 AC 112 ms
4,380 KB
testcase_67 AC 29 ms
4,384 KB
testcase_68 AC 13 ms
4,380 KB
testcase_69 AC 13 ms
4,384 KB
testcase_70 AC 12 ms
4,384 KB
testcase_71 AC 12 ms
4,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2099.cc:  No.2099 [Cherry Alpha B] Time Machine - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

template <typename T>
T gcd(T m, T n) {  // m >= 0, n >= 0
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}

template <typename T>
T lcm(T m, T n) {
  return m * n / gcd<T>(m, n);
}

inline ll forward(ll t, int x, int a) {
  return t / a * x + t % a;
}

/* main */

int main() {
  int t, x, a, y, b;
  scanf("%d%d%d%d%d", &t, &x, &a, &y, &b);

  ll dd = 0;
  if (t < 0) {
    int s = (-t + b - 1) / b * b;
    dd = (ll)s / b * y;
    t += s;
  }

  int c = lcm<ll>(a, b) / b;
  ll mind = LINF;

  for (int i = 0; i < c; i++) {
    ll d = (ll)y * i + forward(t + (ll)b * i, x, a);
    mind = min(mind, d);
  }

  printf("%lld\n", mind + dd);

  return 0;
}
0