結果
| 問題 | No.45 回転寿司 |
| ユーザー |
tsuchinaga
|
| 提出日時 | 2019-03-28 16:02:38 |
| 言語 | Go (1.25.5) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,115 bytes |
| 記録 | |
| コンパイル時間 | 12,749 ms |
| コンパイル使用メモリ | 221,048 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 04:52:44 |
| 合計ジャッジ時間 | 12,063 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 2 WA * 28 |
ソースコード
package main
import (
"fmt"
"math"
)
func main() {
var n, a int
_, _ = fmt.Scan(&n)
nums := make([]int, n)
for i := range nums {
_, _ = fmt.Scan(&a)
nums[i] = a
}
// fmt.Println(nums)
// 皿を取ることで得られる利益
gains := make(map[int]int, 0)
for i := 0; i < n; i++ {
gains[i] = nums[i]
if i != n-1 {
gains[i] -= nums[i+1]
}
if i != 0 {
gains[i] -= nums[i-1]
}
}
// fmt.Println(gains)
ans := 0
for n > 0 {
max := math.MinInt64
maxI := -1
for i := 0; i < len(nums); i++ {
if a, ok := gains[i]; ok {
if maxI < 0 || max < a {
maxI = i
max = a
}
}
}
if maxI != len(nums)-1 {
if _, ok := gains[maxI+1]; ok {
if _, ok := gains[maxI+2]; ok {
gains[maxI+2] += nums[maxI+1]
}
n--
delete(gains, maxI+1)
}
}
if maxI != 0 {
if _, ok := gains[maxI-1]; ok {
if _, ok := gains[maxI-2]; ok {
gains[maxI-2] += nums[maxI-1]
}
n--
delete(gains, maxI-1)
}
}
ans += nums[maxI]
delete(gains, maxI)
n--
// fmt.Println(maxI, max, nums[maxI], ans, gains)
}
fmt.Println(ans)
}
tsuchinaga