結果

問題 No.118 門松列(2)
ユーザー KinaKina
提出日時 2021-02-06 17:37:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 180 ms / 5,000 ms
コード長 2,432 bytes
コンパイル時間 2,980 ms
コンパイル使用メモリ 86,528 KB
実行使用メモリ 56,736 KB
最終ジャッジ日時 2023-09-16 03:37:33
合計ジャッジ時間 8,023 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
52,840 KB
testcase_01 AC 180 ms
56,456 KB
testcase_02 AC 170 ms
56,516 KB
testcase_03 AC 171 ms
55,700 KB
testcase_04 AC 174 ms
55,956 KB
testcase_05 AC 171 ms
54,480 KB
testcase_06 AC 63 ms
49,984 KB
testcase_07 AC 56 ms
49,952 KB
testcase_08 AC 55 ms
50,048 KB
testcase_09 AC 167 ms
56,380 KB
testcase_10 AC 109 ms
52,552 KB
testcase_11 AC 111 ms
55,048 KB
testcase_12 AC 104 ms
53,072 KB
testcase_13 AC 101 ms
52,620 KB
testcase_14 AC 170 ms
56,492 KB
testcase_15 AC 77 ms
52,092 KB
testcase_16 AC 146 ms
56,048 KB
testcase_17 AC 102 ms
52,688 KB
testcase_18 AC 112 ms
54,636 KB
testcase_19 AC 141 ms
55,920 KB
testcase_20 AC 140 ms
55,596 KB
testcase_21 AC 169 ms
56,736 KB
testcase_22 AC 115 ms
52,768 KB
testcase_23 AC 163 ms
56,588 KB
testcase_24 AC 123 ms
54,652 KB
testcase_25 AC 145 ms
56,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		var A = new int[N];
		Arrays.setAll(A, $ -> Integer.parseInt(sc.get()));

		var bucket = new int[101];
		for (int i : A) {
			bucket[i]++;
		}

		long combination = 0;
		for (int i = 0; i < bucket.length; i++) {
			int low = bucket[i];
			if (low > 0)
				for (int j = i + 1; j < bucket.length; j++) {
					int middle = bucket[j];
					if (middle > 0)
						for (int k = j + 1; k < bucket.length; k++) {
							int high = bucket[k];
							if (high <= 0) continue;

							combination += (long) low * middle * high;
						}
				}
		}
		System.out.println(combination % MOD);
	}

	static final int MOD = 1000000007;

	int mod(long val) {
		return Math.floorMod(val, MOD);
	}

	int add(long a, long b) {
		return mod(a + b);
	}

	int sub(long a, long b) {
		return add(a, -b);
	}

	int mul(long a, long b) {
		return mod(a * b);
	}

	int pow(long a, long n) {
		int res = 1;
		for (; n > 0; n /= 2) {
			if (n % 2 == 1) res = mul(res, a);
			a = mul(a, a);
		}
		return res;
	}

	long[] factorial;
	long[] invFactorial;
	long[] inverse;

	void initFactorial(int max) {
		factorial = new long[max];
		invFactorial = new long[max];
		inverse = new long[max];
		factorial[0] = factorial[1] = 1;
		invFactorial[0] = invFactorial[1] = 1;
		inverse[1] = 1;
		for (int i = 2; i < max; i++) {
			factorial[i] = mul(factorial[i - 1], i);
			long inv = inverse[i] = sub(MOD, mul(inverse[MOD % i], MOD / i));
			invFactorial[i] = mul(invFactorial[i - 1], inv);
		}
	}

	int div(long a, int b) {
		return mul(a, inverse != null && b < inverse.length ? inverse[b] : pow(b, MOD - 2));
	}

	int ncr(int n, int r) {
		if (n < r) return 0;
		if (n < 0 || r < 0) return 0;
		return mul(factorial[n], mul(invFactorial[r], invFactorial[n - r]));
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}
0