結果

問題 No.334 門松ゲーム
ユーザー yukirinyukirin
提出日時 2016-01-26 14:35:01
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 2,001 bytes
コンパイル時間 11,935 ms
コンパイル使用メモリ 228,280 KB
実行使用メモリ 20,736 KB
最終ジャッジ日時 2024-04-19 04:34:22
合計ジャッジ時間 12,087 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 WA -
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 49 ms
18,816 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 14 ms
5,888 KB
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 {
		if len(v.cols) == 0 {
			s := fmt.Sprintf("%v", v.index)
			fmt.Println(s[1 : len(s)-1])
			return
		}
		for _, c := range v.cols {
			for _, r := range c.cols {
				if len(r.cols) == 0 {
					s := fmt.Sprintf("%v", v.index)
					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)
}
0