結果

問題 No.118 門松列(2)
ユーザー yukirinyukirin
提出日時 2016-03-02 02:36:50
言語 Go
(1.22.1)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,084 bytes
コンパイル時間 11,169 ms
コンパイル使用メモリ 221,112 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 06:32:06
合計ジャッジ時間 12,428 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 17 ms
6,816 KB
testcase_02 AC 15 ms
6,944 KB
testcase_03 AC 15 ms
6,940 KB
testcase_04 AC 15 ms
6,940 KB
testcase_05 AC 15 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 17 ms
6,940 KB
testcase_10 AC 11 ms
6,940 KB
testcase_11 AC 11 ms
6,940 KB
testcase_12 AC 10 ms
6,940 KB
testcase_13 AC 10 ms
6,944 KB
testcase_14 AC 16 ms
6,940 KB
testcase_15 AC 9 ms
6,940 KB
testcase_16 AC 14 ms
6,940 KB
testcase_17 AC 10 ms
6,940 KB
testcase_18 AC 10 ms
6,940 KB
testcase_19 AC 11 ms
6,940 KB
testcase_20 AC 13 ms
6,940 KB
testcase_21 AC 14 ms
6,944 KB
testcase_22 AC 10 ms
6,940 KB
testcase_23 AC 14 ms
6,944 KB
testcase_24 AC 10 ms
6,940 KB
testcase_25 AC 12 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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, 0, n)
	m := make(map[int]int64)
	c, mod := int64(0), int64(1e9+7)

	for i := 0; i < n; i++ {
		m[nextInt()]++
	}

	for k := range m {
		bamboos = append(bamboos, k)
	}

	f := func(a []int) {
		if isKD(a) {
			c += 1 * m[a[0]] * m[a[1]] * m[a[2]]
		}
	}
	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