結果

問題 No.90 品物の並び替え
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-08 14:51:51
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 971 bytes
コンパイル時間 10,942 ms
コンパイル使用メモリ 210,596 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 19:39:35
合計ジャッジ時間 11,119 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func main() {
	type Score struct {
		i1, i2, s int
	}

	var n, m, i1, i2, s int
	_, _ = fmt.Scan(&n, &m)

	scores := make(map[int]Score)
	for i := 0; i < m; i++ {
		_, _ = fmt.Scan(&i1, &i2, &s)
		scores[i1*10+i2] = Score{i1, i2, s}
	}

	list := []int{0}
	total := 0
	for i := 1; i < n; i++ { // 入れる数字
		max := 0
		maxJ := 0
		for j := 0; j <= len(list); j++ { // 入れる位置
			score := 0

			for k := 0; k < len(list); k++ { // 入れた場合に得られるスコア計算
				if k < j {
					score += scores[list[k]*10+i].s
				} else {
					score += scores[i*10+list[k]].s
				}
			}

			if max < score {
				max = score
				maxJ = j
			}
		}

		// fmt.Println(list, i, max, maxJ, total)
		total += max
		switch maxJ {
		case 0:
			list = append([]int{i}, list...)
		case len(list):
			list = append(list, i)
		default:
			list = append(list[:maxJ-1], append([]int{i}, list[maxJ:]...)...)
		}
	}

	fmt.Println(total)
}
0