結果

問題 No.604 誕生日のお小遣い
ユーザー kichirb3kichirb3
提出日時 2018-03-16 20:49:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 968 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 69,740 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 14:33:27
合計ジャッジ時間 1,381 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,948 KB
testcase_23 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.604 誕生日のお小遣い
// https://yukicoder.me/problems/no/604
//
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

unsigned long long int solve(unsigned long long int A, unsigned long long int B, unsigned long long int C);


int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    unsigned long long A, B, C;
    cin >> A >> B >> C;
    unsigned long long ans = solve(A, B, C);
    cout << ans << endl;
}

unsigned long long int solve(unsigned long long int A, unsigned long long int B, unsigned long long int C) {
    if (A == 1) {
        unsigned long long ans = C / B;
        if (C % B != 0)
            ++ans;
        return ans;
    }
    
    unsigned long long cycle_income = B + (A - 1);
    unsigned long long cycle = C / cycle_income;
    unsigned long long ans1 = C - (cycle_income * cycle) + A * cycle;
    unsigned long long ans2 = (cycle + 1) * A;
    return min(ans1, ans2);
}
0