結果

問題 No.115 遠足のおやつ
コンテスト
ユーザー むらため
提出日時 2019-01-23 12:16:38
言語 Nim
(2.2.8)
コンパイル:
nim --nimcache=~ --hints:off -o:a.out -d:release cpp _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 704 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,585 ms
コンパイル使用メモリ 70,360 KB
実行使用メモリ 11,300 KB
最終ジャッジ日時 2026-03-22 09:18:12
合計ジャッジ時間 42,823 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sequtils,strutils,algorithm
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    var k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord

let n = scan()
var solved = newSeq[int]()
proc solve(sum,cnt,start:int) : bool =
  if cnt == 1 :
    if sum < start : return false
    if sum > n : return false
    solved &= sum
    return true
  for i in start..sum:
    let ok = solve(sum-i,cnt-1,i+1)
    if not ok : continue
    solved &= i
    return true
  return false
let sum = scan()
let cnt = scan()
let ans = solve(sum,cnt,1)
if not ans : echo -1
else: echo solved.reversed().mapIt($it).join(" ")
0