結果

問題 No.118 門松列(2)
ユーザー yukirinyukirin
提出日時 2016-03-02 02:30:01
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 975 bytes
コンパイル時間 12,933 ms
コンパイル使用メモリ 235,772 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-19 06:31:52
合計ジャッジ時間 25,072 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	bamboos := make([]int, n)
	c, mod := int64(0), int64(1e9+7)

	for i := range bamboos {
		bamboos[i] = nextInt()
	}

	f := func(a []int) {
		if isKD(a) {
			c++
		}
	}
	comb(bamboos, 3, f)
	fmt.Println(c % mod)
}

func isKD(a []int) bool {
	if a[0] == a[1] || a[1] == a[2] || a[0] == a[2] {
		return false
	}
	return true
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}

func comb(a []int, r int, fn func([]int)) {
	if r > len(a) || r < 1 {
		return
	}

	var f func([]int, int, int)
	f = func(ret []int, last, c int) {
		if c == 0 {
			fn(ret)
			return
		}

		c--
		for i, v := range a[last : len(a)-c] {
			ret[r-c-1] = v
			f(ret, i+last+1, c)
		}
	}

	ret := make([]int, r)
	f(ret, 0, r)
}
0