結果

問題 No.335 門松宝くじ
ユーザー cielciel
提出日時 2016-01-16 00:09:16
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 514 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 11,936 KB
実行使用メモリ 20,596 KB
最終ジャッジ日時 2023-10-19 23:47:02
合計ジャッジ時間 4,136 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
20,464 KB
testcase_01 AC 91 ms
16,116 KB
testcase_02 AC 87 ms
16,116 KB
testcase_03 AC 89 ms
16,116 KB
testcase_04 AC 87 ms
16,116 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
def value(a)
	idxes={}
	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,a[idxi]],[idxj,a[idxj]],[idxk,a[idxk]]].sort
				if (b[0][1]<b[1][1]&&b[2][1]<b[1][1]) || (b[0][1]>b[1][1]&&b[2][1]>b[1][1])
					r=[r,a[idxk]].max
				end
			}
			ret+=[r,i,j].max if r>0
		}
	}
	ret
end
N,M=gets.split.map(&:to_i)
p M.times.max_by{|i|value(gets.split.map(&:to_i))}
0