結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
mmmppp
|
| 提出日時 | 2017-03-07 19:20:32 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 719 bytes |
| コンパイル時間 | 53 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 14,016 KB |
| 最終ジャッジ日時 | 2024-06-23 17:18:45 |
| 合計ジャッジ時間 | 6,884 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 TLE * 1 -- * 8 |
コンパイルメッセージ
Syntax OK
ソースコード
N,T,*A = $<.read.split.map &:to_i
h = {}
s = ?+*(N - 1)
def succ s
if s[-1] == ?+
s[0..-2] + ?*
else
succ(s[0..-2]) + ?+
end
end
def culc a, s
l = a.size-1
sum = a[0]
l.times{|i|
case s[i]
when ?+ then sum+=a[i+1]
when ?* then sum*=a[i+1]
end
}
sum
end
loop{
break if culc(A, s) == T
if (2..N).each{|j|
partial_sum = culc(A[0, j], s[0, j - 1])
if h[[j, partial_sum]]
s = succ(s[0,j - 1]) + ?+*(N - j)
break
elsif s[-1] == ?*
s[/\*+$/].size.times{|k|
partial_sum = culc(A[0, N - j], s[0, N - j - 1])
h[[N - j, partial_sum]] = partial_sum
}
end
}
s = succ s
end
}
$><<s
mmmppp