結果

問題 No.365 ジェンガソート
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-15 12:39:13
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 690 bytes
コンパイル時間 15,531 ms
コンパイル使用メモリ 209,388 KB
実行使用メモリ 12,160 KB
最終ジャッジ日時 2023-09-11 03:58:11
合計ジャッジ時間 20,646 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
}
0