結果
問題 | No.118 門松列(2) |
ユーザー | Kina |
提出日時 | 2021-02-06 17:37:50 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 199 ms / 5,000 ms |
コード長 | 2,432 bytes |
コンパイル時間 | 2,644 ms |
コンパイル使用メモリ | 88,544 KB |
実行使用メモリ | 45,188 KB |
最終ジャッジ日時 | 2024-07-03 04:57:54 |
合計ジャッジ時間 | 7,772 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
39,260 KB |
testcase_01 | AC | 198 ms
44,904 KB |
testcase_02 | AC | 194 ms
44,676 KB |
testcase_03 | AC | 194 ms
44,732 KB |
testcase_04 | AC | 195 ms
44,752 KB |
testcase_05 | AC | 195 ms
44,700 KB |
testcase_06 | AC | 58 ms
37,116 KB |
testcase_07 | AC | 57 ms
37,212 KB |
testcase_08 | AC | 58 ms
37,352 KB |
testcase_09 | AC | 193 ms
44,628 KB |
testcase_10 | AC | 116 ms
39,840 KB |
testcase_11 | AC | 129 ms
40,452 KB |
testcase_12 | AC | 109 ms
39,744 KB |
testcase_13 | AC | 109 ms
39,380 KB |
testcase_14 | AC | 199 ms
44,624 KB |
testcase_15 | AC | 89 ms
38,096 KB |
testcase_16 | AC | 153 ms
42,880 KB |
testcase_17 | AC | 103 ms
39,460 KB |
testcase_18 | AC | 133 ms
40,428 KB |
testcase_19 | AC | 155 ms
41,848 KB |
testcase_20 | AC | 153 ms
41,888 KB |
testcase_21 | AC | 168 ms
45,188 KB |
testcase_22 | AC | 116 ms
40,176 KB |
testcase_23 | AC | 161 ms
44,244 KB |
testcase_24 | AC | 133 ms
41,000 KB |
testcase_25 | AC | 135 ms
41,464 KB |
ソースコード
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(); } }