結果
問題 | No.2099 [Cherry Alpha B] Time Machine |
ユーザー |
|
提出日時 | 2022-10-14 22:59:33 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,124 ms / 2,000 ms |
コード長 | 1,062 bytes |
コンパイル時間 | 5,583 ms |
コンパイル使用メモリ | 112,960 KB |
実行使用メモリ | 27,524 KB |
最終ジャッジ日時 | 2024-06-26 16:46:00 |
合計ジャッジ時間 | 22,692 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 72 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);}}