結果

問題 No.825 賢いお買い物
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-05-07 11:24:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,100 bytes
コンパイル時間 3,728 ms
コンパイル使用メモリ 71,828 KB
実行使用メモリ 56,192 KB
最終ジャッジ日時 2023-09-14 16:24:40
合計ジャッジ時間 6,153 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,452 KB
testcase_01 AC 128 ms
55,604 KB
testcase_02 AC 124 ms
55,864 KB
testcase_03 AC 124 ms
55,744 KB
testcase_04 AC 125 ms
55,896 KB
testcase_05 AC 125 ms
55,776 KB
testcase_06 AC 126 ms
55,800 KB
testcase_07 AC 126 ms
55,948 KB
testcase_08 AC 128 ms
55,708 KB
testcase_09 AC 123 ms
55,696 KB
testcase_10 AC 125 ms
55,892 KB
testcase_11 AC 126 ms
55,900 KB
testcase_12 AC 125 ms
55,452 KB
testcase_13 AC 127 ms
55,876 KB
testcase_14 AC 123 ms
55,764 KB
testcase_15 AC 126 ms
55,828 KB
testcase_16 AC 126 ms
55,852 KB
testcase_17 AC 127 ms
55,712 KB
testcase_18 AC 129 ms
55,996 KB
testcase_19 AC 127 ms
55,832 KB
testcase_20 AC 127 ms
56,192 KB
testcase_21 AC 126 ms
55,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int a = stdin.nextInt(); // 1G
        int b = stdin.nextInt(); // 10G
        int c = stdin.nextInt();
        
        // x: 1Gの枚数
        // y: 10Gの枚数
        // z: 購入する商品の価格
        int ans = Integer.MAX_VALUE;
        for (int x = 0; x <= a; x++) {
            for (int y = 0; y <= b; y++) {
                for (int z = 1; z <= a + b * 10; z++) {
                    if (x + y * 10 < z) continue; // 購入不能
                    int p = (x + y * 10 - z) / 10; // おつりの1Gの枚数
                    int q = (x + y * 10 - z) % 10; // おつりの10Gの枚数
                    if (a + b - (x + y) + (p + q) == c) {
                        ans = Math.min(ans, z);
                    }
                }
            }
        }
        
        if (ans == Integer.MAX_VALUE) {
            System.out.println("Impossible");
        } else {
            System.out.println(ans);
        }
        
    }
}
0