結果

問題 No.825 賢いお買い物
ユーザー tentententen
提出日時 2021-02-10 08:59:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 72,636 KB
実行使用メモリ 56,360 KB
最終ジャッジ日時 2023-09-22 02:03:54
合計ジャッジ時間 6,002 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
53,496 KB
testcase_01 AC 132 ms
55,868 KB
testcase_02 AC 124 ms
55,828 KB
testcase_03 AC 125 ms
55,756 KB
testcase_04 AC 125 ms
55,696 KB
testcase_05 AC 125 ms
55,496 KB
testcase_06 AC 123 ms
55,820 KB
testcase_07 AC 125 ms
56,360 KB
testcase_08 AC 127 ms
55,716 KB
testcase_09 AC 124 ms
56,000 KB
testcase_10 AC 126 ms
56,128 KB
testcase_11 AC 127 ms
55,908 KB
testcase_12 AC 124 ms
55,716 KB
testcase_13 AC 125 ms
55,752 KB
testcase_14 AC 123 ms
55,900 KB
testcase_15 AC 124 ms
55,904 KB
testcase_16 AC 125 ms
55,784 KB
testcase_17 AC 124 ms
55,760 KB
testcase_18 AC 127 ms
55,784 KB
testcase_19 AC 124 ms
54,244 KB
testcase_20 AC 127 ms
55,852 KB
testcase_21 AC 125 ms
55,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int ans = Integer.MAX_VALUE / 2;
        for (int i = 1; i <= a + b * 10; i++) {
            for (int j = 0; j <= a; j++) {
                for (int k = 0; k <= b; k++) {
                    int value = j + 10 * k;
                    if (value == 0) {
                        continue;
                    }
                    if (getCount(value - i) + a - j + b - k == c) {
                        ans = Math.min(ans, i);
                    }
                }
            }
        }
        if (ans >= Integer.MAX_VALUE / 2) {
            System.out.println("Impossible");
        } else {
            System.out.println(ans);
        }
    }
    
    static int getCount(int x) {
        if (x < 0) {
            return Integer.MAX_VALUE / 2;
        } else {
            return x % 10 + x / 10;
        }
    }
}
0