結果
問題 | No.1311 Reverse Permutation Index |
ユーザー | ciel |
提出日時 | 2020-06-07 01:29:19 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 79 ms / 1,500 ms |
コード長 | 568 bytes |
コンパイル時間 | 643 ms |
コンパイル使用メモリ | 11,348 KB |
実行使用メモリ | 15,336 KB |
最終ジャッジ日時 | 2023-08-25 02:33:00 |
合計ジャッジ時間 | 1,553 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 78 ms
15,280 KB |
testcase_01 | AC | 75 ms
15,328 KB |
testcase_02 | AC | 76 ms
15,144 KB |
testcase_03 | AC | 79 ms
15,336 KB |
testcase_04 | AC | 78 ms
15,148 KB |
testcase_05 | AC | 76 ms
15,296 KB |
testcase_06 | AC | 76 ms
15,176 KB |
testcase_07 | AC | 75 ms
15,300 KB |
コンパイルメッセージ
Main.rb:38: warning: `*' interpreted as argument prefix Syntax OK
ソースコード
#!/usr/bin/ruby def perm2idx(a) lst=[*1..a.size] raise if lst!=a.sort fact=[1] (1...a.size).each{|i|fact<<fact[-1]*i} fact.reverse! r=0 a.each_with_index{|e,i| idx=lst.index(e) r+=fact[i]*idx lst.delete_at(idx) } r end def idx2perm(n,siz) lst=[*1..siz] fact=[1] (1...siz).each{|i|fact<<fact[-1]*i} fact.reverse! raise if fact[0]*siz<=n a=[] fact.each{|e| z=n/e n%=e a<<lst[z] lst.delete_at(z) } a end def reverseperm(a) r=[nil]*a.size a.size.times{|i| r[a[i]-1]=i+1 } r end p perm2idx reverseperm idx2perm *gets.split.map(&:to_i)