結果

問題 No.335 門松宝くじ
ユーザー cielciel
提出日時 2016-01-16 00:20:06
言語 Crystal
(1.11.2)
結果
TLE  
実行時間 -
コード長 557 bytes
コンパイル時間 19,025 ms
コンパイル使用メモリ 259,472 KB
実行使用メモリ 4,592 KB
最終ジャッジ日時 2023-09-13 09:03:22
合計ジャッジ時間 21,451 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,592 KB
testcase_01 AC 3 ms
4,480 KB
testcase_02 AC 2 ms
4,496 KB
testcase_03 AC 2 ms
4,484 KB
testcase_04 AC 2 ms
4,552 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ruby
def value(n : Int32, a : Array(Int32))
	idxes=Hash(Int32,Int32).new
	a.each_with_index{|e,i|idxes[e]=i}
	ret=0
	1.upto(n-1){|i|
		idxi=idxes[i]
		(i+1).upto(n){|j|
			idxj=idxes[j]
			r=0
			(0..n-1).each{|idxk|
				next if idxk==idxi || idxk==idxj
				b=[[idxi,i],[idxj,j],[idxk,a[idxk]]].sort.map{|e|e[1]}
				if (b[0]<b[1]&&b[2]<b[1]) || (b[0]>b[1]&&b[2]>b[1])
					r=[r,a[idxk]].max
				end
			}
			ret+=[r,i,j].max if r>0
		}
	}
	ret
end
n,m=gets.not_nil!.split.map(&.to_i)
p (0..m-1).max_by{|i|value(n,gets.not_nil!.split.map(&.to_i))}
0