結果
問題 | No.825 賢いお買い物 |
ユーザー |
![]() |
提出日時 | 2021-02-10 08:59:08 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 119 ms / 2,000 ms |
コード長 | 1,049 bytes |
コンパイル時間 | 1,856 ms |
コンパイル使用メモリ | 74,480 KB |
実行使用メモリ | 41,368 KB |
最終ジャッジ日時 | 2024-07-07 18:52:31 |
合計ジャッジ時間 | 5,012 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
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; } } }