結果

問題 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,153 ms
コンパイル使用メモリ 69,236 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-08-03 05:55:27
合計ジャッジ時間 9,160 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 1 TLE * 1 -- * 38
権限があれば一括ダウンロードができます

ソースコード

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