結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー 👑 kakel-sankakel-san
提出日時 2022-10-14 22:59:33
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,130 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 2,549 ms
コンパイル使用メモリ 64,016 KB
実行使用メモリ 25,712 KB
最終ジャッジ日時 2023-09-08 23:21:45
合計ジャッジ時間 21,430 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
21,560 KB
testcase_01 AC 58 ms
21,680 KB
testcase_02 AC 59 ms
21,512 KB
testcase_03 AC 191 ms
21,304 KB
testcase_04 AC 58 ms
21,612 KB
testcase_05 AC 59 ms
23,548 KB
testcase_06 AC 259 ms
21,460 KB
testcase_07 AC 415 ms
21,492 KB
testcase_08 AC 58 ms
23,576 KB
testcase_09 AC 58 ms
23,712 KB
testcase_10 AC 58 ms
19,388 KB
testcase_11 AC 58 ms
21,452 KB
testcase_12 AC 57 ms
23,600 KB
testcase_13 AC 191 ms
21,472 KB
testcase_14 AC 59 ms
21,512 KB
testcase_15 AC 58 ms
21,668 KB
testcase_16 AC 258 ms
21,676 KB
testcase_17 AC 414 ms
19,584 KB
testcase_18 AC 59 ms
21,548 KB
testcase_19 AC 58 ms
21,460 KB
testcase_20 AC 58 ms
21,640 KB
testcase_21 AC 57 ms
21,504 KB
testcase_22 AC 58 ms
19,448 KB
testcase_23 AC 57 ms
23,604 KB
testcase_24 AC 57 ms
21,456 KB
testcase_25 AC 57 ms
23,668 KB
testcase_26 AC 57 ms
21,504 KB
testcase_27 AC 59 ms
21,592 KB
testcase_28 AC 190 ms
23,552 KB
testcase_29 AC 57 ms
21,552 KB
testcase_30 AC 58 ms
21,380 KB
testcase_31 AC 256 ms
21,704 KB
testcase_32 AC 415 ms
21,448 KB
testcase_33 AC 193 ms
21,744 KB
testcase_34 AC 58 ms
21,380 KB
testcase_35 AC 58 ms
21,520 KB
testcase_36 AC 257 ms
23,372 KB
testcase_37 AC 413 ms
21,632 KB
testcase_38 AC 58 ms
21,528 KB
testcase_39 AC 56 ms
19,632 KB
testcase_40 AC 57 ms
21,516 KB
testcase_41 AC 57 ms
21,524 KB
testcase_42 AC 57 ms
21,496 KB
testcase_43 AC 57 ms
19,636 KB
testcase_44 AC 58 ms
21,504 KB
testcase_45 AC 57 ms
21,632 KB
testcase_46 AC 58 ms
21,508 KB
testcase_47 AC 58 ms
23,472 KB
testcase_48 AC 191 ms
21,464 KB
testcase_49 AC 58 ms
21,704 KB
testcase_50 AC 57 ms
23,544 KB
testcase_51 AC 256 ms
21,440 KB
testcase_52 AC 414 ms
21,324 KB
testcase_53 AC 58 ms
23,516 KB
testcase_54 AC 57 ms
21,632 KB
testcase_55 AC 59 ms
21,636 KB
testcase_56 AC 859 ms
21,760 KB
testcase_57 AC 904 ms
21,700 KB
testcase_58 AC 907 ms
21,560 KB
testcase_59 AC 861 ms
19,692 KB
testcase_60 AC 460 ms
21,500 KB
testcase_61 AC 481 ms
21,676 KB
testcase_62 AC 1,092 ms
19,596 KB
testcase_63 AC 1,130 ms
21,536 KB
testcase_64 AC 679 ms
21,388 KB
testcase_65 AC 860 ms
23,480 KB
testcase_66 AC 678 ms
21,640 KB
testcase_67 AC 204 ms
21,460 KB
testcase_68 AC 118 ms
25,712 KB
testcase_69 AC 121 ms
21,444 KB
testcase_70 AC 117 ms
21,756 KB
testcase_71 AC 118 ms
23,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var t = NN;
        var c = NList;
        var (x, a) = (c[0], c[1]);
        c = NList;
        var (y, b) = (c[0], c[1]);
        WriteLine(Time(t, x, a, y, b));
    }
    static long Time(int t, long x, long a, long y, long b)
    {
        var res = t < 0 ? long.MaxValue : t;
        for (var i = 0; a * i < Math.Max(0, t) + a * b / GCD(a, b); ++i)
        {
            var j = 0L;
            if (a * i > t) j = (a * i - t + b - 1) / b;
            res = Math.Min(res, x * i + y * j + t - (a * i - b * j));
        }
        return res;
    }
    static long GCD(long a, long b)
    {
        if (a < b) return GCD(b, a);
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }
}
0