結果

問題 No.825 賢いお買い物
ユーザー むらためむらため
提出日時 2019-05-20 04:17:01
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 66,460 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 18:33:23
合計ジャッジ時間 3,146 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import sequtils
template times*(n:int,body) = (for _ in 0..<n: body)
template `max=`*(x,y) = x = max(x,y)
template `min=`*(x,y) = x = min(x,y)
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" ,discardable.}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10 * result + k.ord - '0'.ord

proc solve(a,b,c:int):int =
  # A 10B -> A+B=C
  # 15 + 15*10
  for x in 1..a+b*10:
    for ia in 0..a:
      for ib in 0..b:
        # x円のものを ia+ib*10円で払う
        let g = ia + ib*10 - x
        if g < 0 : continue
        let res = (a-ia) + (b-ib) + (g mod 10) + (g div 10)
        if res != c : continue
        return x
  return -1
# const ABC = (
#   proc():seq[seq[seq[int]]] =
#     result = newSeqWith(21,newSeqWith(21,newSeqWith(101,0)))
#     for a in 0..20:
#       for b in 0..20:
#         for c in 0..100:
#           result[a][b][c] = solve(a,b,c)
#   )()
let a = scan()
let b = scan()
let c = scan()
let ans = solve(a,b,c)
if ans == -1 : echo "Impossible"
else: echo ans
0