結果

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

テストケース

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

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)

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)
	}

	comb(bamboos, 3, func(a []int) {
		c += m[a[0]] * m[a[1]] * m[a[2]] % mod
	})

	fmt.Println(c % mod)
}

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