結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-01-26 14:00:59 |
| 言語 | Go (1.23.4) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,001 bytes |
| コンパイル時間 | 12,283 ms |
| コンパイル使用メモリ | 226,164 KB |
| 実行使用メモリ | 20,864 KB |
| 最終ジャッジ日時 | 2024-10-10 21:05:34 |
| 合計ジャッジ時間 | 11,722 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 4 WA * 9 |
ソースコード
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
type collection struct {
index []int
val []int
cols []*collection
}
var sc = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)
func main() {
sc.Split(bufio.ScanWords)
n := nextInt()
var nums []int
for i := 0; i < n; i++ {
nums = append(nums, nextInt())
}
c := &collection{
val: nums,
}
dfs(c)
for _, v := range c.cols {
all := true
for _, c := range v.cols {
sub := false
for _, r := range c.cols {
if len(r.cols) == 0 {
sub = true
break
}
}
if !sub {
all = false
break
}
}
if all {
s := fmt.Sprintf("%v", v)
fmt.Println(s[1 : len(s)-1])
return
}
}
fmt.Println(-1)
}
func dfs(c *collection) {
for i := 0; i < len(c.val)-2; i++ {
for j := i + 1; j < len(c.val)-1; j++ {
for k := j + 1; k < len(c.val); k++ {
if !check(c.val[i], c.val[j], c.val[k]) {
continue
}
col := &collection{
index: []int{i, j, k},
}
col.val = append(col.val, c.val[:i]...)
col.val = append(col.val, c.val[i+1:j]...)
col.val = append(col.val, c.val[j+1:k]...)
col.val = append(col.val, c.val[k+1:]...)
c.cols = append(c.cols, col)
dfs(col)
}
}
}
}
func check(a, b, c int) bool {
if (b < a && a < c) || (c < a && a < b) {
return true
}
if (a < c && c < b) || (b < c && c < a) {
return true
}
return false
}
func nextLine() string {
sc.Scan()
return sc.Text()
}
func nextInt() int {
i, _ := strconv.Atoi(nextLine())
return i
}
func nextInt64() int64 {
i, _ := strconv.ParseInt(nextLine(), 10, 64)
return i
}
func nextUint64() uint64 {
i, _ := strconv.ParseUint(nextLine(), 10, 64)
return i
}
func nextFloat() float64 {
f, _ := strconv.ParseFloat(nextLine(), 64)
return f
}
func readLine() string {
buf := make([]byte, 0, 1000000)
for {
l, p, e := rdr.ReadLine()
if e != nil {
panic(e)
}
buf = append(buf, l...)
if !p {
break
}
}
return string(buf)
}