結果

問題 No.825 賢いお買い物
ユーザー むらためむらため
提出日時 2019-05-20 04:14:21
言語 Nim
(2.2.0)
結果
WA  
実行時間 -
コード長 1,069 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 61,272 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-02 01:34:47
合計ジャッジ時間 3,152 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
/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
  var ans = -1
  for x in 1..a+b:
    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