結果
問題 |
No.693 square1001 and Permutation 2
|
ユーザー |
|
提出日時 | 2018-07-01 20:55:51 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 91 ms / 2,000 ms |
コード長 | 418 bytes |
コンパイル時間 | 96 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-07-01 01:16:19 |
合計ジャッジ時間 | 1,868 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 |
コンパイルメッセージ
Syntax OK
ソースコード
n = gets.to_i a = gets.chomp.split.map(&:to_i) ans = 0 ary = [] n.times do |i| ary[i] = a.count(i+1) end n.times do |i| if ary[i] > 1 surplus = ary[i] - 1 prei = i while surplus > 0 i += 1 while ary[i] != 0 ary[i] = 1 ans += i - prei surplus -= 1 end next end if ary[i] == 0 ary[i] = 1 prei = i i += 1 while ary[i] < 2 ary[i] -= 1 ans += i - prei next end end print ans