結果
問題 | No.825 賢いお買い物 |
ユーザー |
![]() |
提出日時 | 2019-05-07 11:24:44 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 139 ms / 2,000 ms |
コード長 | 1,100 bytes |
コンパイル時間 | 2,195 ms |
コンパイル使用メモリ | 75,056 KB |
実行使用メモリ | 41,416 KB |
最終ジャッジ日時 | 2024-07-01 23:32:26 |
合計ジャッジ時間 | 6,005 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
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); } } }