結果
| 問題 | No.365 ジェンガソート | 
| コンテスト | |
| ユーザー |  tsuchinaga | 
| 提出日時 | 2019-03-15 12:39:13 | 
| 言語 | Go (1.23.4) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 690 bytes | 
| コンパイル時間 | 10,434 ms | 
| コンパイル使用メモリ | 234,984 KB | 
| 実行使用メモリ | 14,516 KB | 
| 最終ジャッジ日時 | 2024-06-28 18:29:45 | 
| 合計ジャッジ時間 | 15,444 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 TLE * 1 -- * 24 | 
ソースコード
package main
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
func main() {
	var n int
	_, _ = fmt.Scan(&n)
	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	nums := make(map[int]int, 0) // 数字がどこにあるか
	for i := 0; i < n; i++ {
		bs.Scan()
		a, _ := strconv.Atoi(bs.Text())
		nums[a] = i
	}
	// fmt.Println(nums)
	cnt := 0
	fix := 0
	for {
		end := true
		for i := n - fix; i > 1; i-- {
			if nums[i] > nums[i-1] {
				fix++
			} else {
				end = false
				cnt++
				for j := 1; j <= n; j++ {
					if nums[j] < nums[i-1] {
						nums[j]++
					}
				}
				nums[i-1] = 0
				// fmt.Println(cnt, fix, nums)
			}
		}
		if end {
			break
		}
	}
	fmt.Println(cnt)
}
            
            
            
        