結果

問題 No.176 2種類の切手
ユーザー norioc
提出日時 2020-03-30 00:16:31
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 804 bytes
コンパイル時間 3,232 ms
コンパイル使用メモリ 175,016 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 06:18:00
合計ジャッジ時間 2,835 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

int calc(int a, int b, int t) {
    // ax + by >= t

    int ans = int.max;
    for (int y = 0; ; y++) {
        // b 円の切手の枚数を固定する
        auto t2 = t - b * y;
        if (t2 <= 0) { // b 円の切手だけで t 円超えた
            ans = min(ans, b * y);
            break;
        }

        auto x = (t2 + a - 1) / a;
        ans = min(ans, a * x + b * y);
        if (y == a) break; // これがないと TLE
    }
    return ans;
}

void main() {
    int a, b, t; scan(a, b, t);
    writeln(calc(a, b, t));

}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
0