結果

問題 No.115 遠足のおやつ
コンテスト
ユーザー horiesiniti
提出日時 2018-03-28 09:54:43
言語 Ruby
(4.0.7 + ACL)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
AC  
実行時間 53 ms / 5,000 ms
+ 224µs
コード長 436 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9 ms
コンパイル使用メモリ 8,960 KB
実行使用メモリ 14,720 KB
最終ジャッジ日時 2026-10-10 10:00:11
合計ジャッジ時間 4,085 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:11: warning: ambiguous first argument; put parentheses or a space even after `-` operator
Main.rb:41: warning: ambiguous first argument; put parentheses or a space even after `-` operator
Syntax OK

ソースコード

diff #
raw source code

n,d,k=gets.split.map{|e| e.to_i}
x=[]
sum=0
k.times{|i|
	x<<i+1
	sum+=(i+1)
}


if d<sum || n<k
	puts -1
elsif d==sum
	puts x*" "
else
	k.times{|i|
		p1=k-i-1
		while true
			if sum==d
				break
			end
			if p1==k-1
				if x[p1]==n
					break
				end
			else
				if x[p1]+1==x[p1+1]
					break
				end
			end
			sum+=1
			x[p1]+=1
			if sum==d
				break
			end
		end
		break if sum==d
	}
	if sum==d
		puts x*" "
	else
		puts -1
	end
end
0