結果

問題 No.118 門松列(2)
ユーザー tyochiaityochiai
提出日時 2015-01-19 04:45:14
言語 Go
(1.22.1)
結果
AC  
実行時間 316 ms / 5,000 ms
コード長 731 bytes
コンパイル時間 10,228 ms
コンパイル使用メモリ 233,600 KB
実行使用メモリ 7,836 KB
最終ジャッジ日時 2024-04-18 09:41:25
合計ジャッジ時間 15,133 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
6,812 KB
testcase_01 AC 313 ms
7,828 KB
testcase_02 AC 302 ms
7,832 KB
testcase_03 AC 311 ms
7,828 KB
testcase_04 AC 316 ms
7,832 KB
testcase_05 AC 312 ms
7,828 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 290 ms
7,828 KB
testcase_10 AC 59 ms
6,940 KB
testcase_11 AC 81 ms
6,944 KB
testcase_12 AC 43 ms
6,940 KB
testcase_13 AC 24 ms
6,944 KB
testcase_14 AC 289 ms
7,828 KB
testcase_15 AC 7 ms
6,944 KB
testcase_16 AC 156 ms
6,944 KB
testcase_17 AC 24 ms
6,944 KB
testcase_18 AC 81 ms
6,944 KB
testcase_19 AC 141 ms
6,940 KB
testcase_20 AC 150 ms
6,944 KB
testcase_21 AC 239 ms
7,836 KB
testcase_22 AC 65 ms
6,940 KB
testcase_23 AC 220 ms
7,836 KB
testcase_24 AC 93 ms
6,944 KB
testcase_25 AC 130 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"math"
)

func LenComb2(n int) float64 {
	N := float64(n)
	return float64(N*(N-1)) / float64(2*1)
}

func LenComb3(n int) float64 {
	N := float64(n)
	return float64(N*(N-1)*(N-2)) / float64(3*2*1)
}

func resolve(N int, A []int) int {
	B := make([]int, 101)
	for i := 0; i < N; i++ {
		B[A[i]] += 1
	}

	ret := LenComb3(N)
	for _, m := range B {
		if m <= 1 {
			continue
		}
		if m == 2 {
			ret -= LenComb2(m) * float64(N-m)
			continue
		}
		ret -= LenComb2(m)*float64(N-m) + LenComb3(m)
	}
	return int(math.Mod(ret, float64(1000000007)))
}

func main() {
	var N int

	fmt.Scanf("%d\n", &N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])
	}

	fmt.Println(resolve(N, A))
}
0