結果

問題 No.2015 Stair Counter
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-04-25 15:56:29
言語 Ruby
(3.3.0)
結果
AC  
実行時間 302 ms / 2,000 ms
コード長 574 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 27,264 KB
最終ジャッジ日時 2024-04-26 21:00:32
合計ジャッジ時間 7,041 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
12,416 KB
testcase_01 AC 183 ms
13,312 KB
testcase_02 AC 181 ms
12,800 KB
testcase_03 AC 186 ms
12,800 KB
testcase_04 AC 175 ms
13,312 KB
testcase_05 AC 166 ms
13,440 KB
testcase_06 AC 195 ms
12,544 KB
testcase_07 AC 192 ms
12,416 KB
testcase_08 AC 195 ms
12,672 KB
testcase_09 AC 156 ms
13,184 KB
testcase_10 AC 163 ms
13,184 KB
testcase_11 AC 160 ms
13,312 KB
testcase_12 AC 153 ms
14,060 KB
testcase_13 AC 163 ms
13,696 KB
testcase_14 AC 164 ms
13,940 KB
testcase_15 AC 219 ms
20,864 KB
testcase_16 AC 264 ms
25,472 KB
testcase_17 AC 207 ms
22,912 KB
testcase_18 AC 249 ms
22,784 KB
testcase_19 AC 302 ms
27,008 KB
testcase_20 AC 221 ms
27,264 KB
testcase_21 AC 174 ms
13,184 KB
testcase_22 AC 184 ms
12,544 KB
testcase_23 AC 188 ms
12,800 KB
testcase_24 AC 177 ms
13,184 KB
testcase_25 AC 174 ms
13,440 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:2: warning: assigned but unused variable - ans
Syntax OK

ソースコード

diff #

def f(n,m,xs)
ans="No"
if n==1 then
	return "Yes" if xs[0]==m
	return "No"
elsif n==2 then
	return "Yes" if xs[0]<=xs[1] && xs[1]==m
	return "No"
elsif xs[-1]==m then
	t=m-xs[0]
	return "No" if t<0
	xs=[t]+xs
	n=xs.size
	#
	(1..n-3).each{|i|
		t3=xs[i+1]-xs[i-1]
		t4=xs[i]-t3
		t5=xs[i+2]-t4
		t6=xs[i+1]-t5
		#p [t3,t4,t5,t6]
		return "No" if [t3,t4,t5,t6].any?{|e| e<0}
		xs[i]=t4
		return "No" if(i==n-3 && t5!=xs[i+1])
	}
	
	return "Yes"
end
return "No"
end
t=gets.to_i
t.times{
	a,b=gets.split(" ").map{|e| e.to_i}
	xs=gets.split(" ").map{|e| e.to_i}
	puts f(a,b,xs)
}
0