結果

問題 No.825 賢いお買い物
ユーザー tsuchinagatsuchinaga
提出日時 2019-05-07 11:15:46
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 13,094 ms
コンパイル使用メモリ 202,116 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 16:24:32
合計ジャッジ時間 11,946 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import "fmt"

func main() {
	var a, b, c, ans int
	_, _ = fmt.Scan(&a, &b, &c)

	// bがなければa以上の枚数を作ることが出来ない
	// 所持枚数より9枚以上多い枚数を求められても作ることが出来ない
	if (b == 0 && a < c) || a+b+9 < c {
		fmt.Println("Impossible")
		return
	}

	// bがあって、枚数が足りないなら10Gをばらして枚数を増やしておく
	// ついでに少なくとも1G以上のものを買う必要があるので、なるべく小さな硬貨で1度支払うことを考える
	ans += 1
	if b > 0 && a+b < c || a == 0 {
		a += 9
		b -= 1
	} else if a > 0 {
		a -= 1
	}

	// ここからは減らすだけ
	for a+b != c {
		if (a+b)-c >= 9 && a >= 10 { // 9枚以上多くて、1Gが10枚あれば10G1枚に変えてしまう。
			a -= 10
			b += 1
		} else if a > 0 {
			a -= 1
			ans += 1
		} else if b > 0 {
			b -= 1
			ans += 10
		} else {
			ans = 0
			break
		}
		// fmt.Println(ans, a, b, c)
	}

	if ans == 0 {
		fmt.Println("Impossible")
	} else {
		fmt.Println(ans)
	}
}
0