結果

問題 No.1470 Mex Sum
ユーザー ks2mks2m
提出日時 2021-04-09 21:29:46
言語 Java19
(openjdk 21)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 73,688 KB
実行使用メモリ 68,056 KB
最終ジャッジ日時 2023-09-07 09:57:48
合計ジャッジ時間 14,922 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,400 KB
testcase_01 AC 43 ms
49,272 KB
testcase_02 AC 94 ms
50,588 KB
testcase_03 AC 94 ms
52,644 KB
testcase_04 AC 99 ms
54,716 KB
testcase_05 AC 96 ms
52,672 KB
testcase_06 AC 97 ms
54,556 KB
testcase_07 AC 93 ms
54,080 KB
testcase_08 AC 93 ms
54,612 KB
testcase_09 AC 96 ms
54,448 KB
testcase_10 AC 97 ms
54,404 KB
testcase_11 AC 99 ms
52,552 KB
testcase_12 AC 244 ms
66,420 KB
testcase_13 AC 240 ms
67,504 KB
testcase_14 AC 249 ms
66,704 KB
testcase_15 AC 259 ms
66,548 KB
testcase_16 AC 229 ms
66,520 KB
testcase_17 AC 242 ms
67,012 KB
testcase_18 AC 235 ms
67,336 KB
testcase_19 AC 240 ms
66,924 KB
testcase_20 AC 249 ms
67,656 KB
testcase_21 AC 237 ms
66,728 KB
testcase_22 AC 249 ms
67,020 KB
testcase_23 AC 280 ms
67,952 KB
testcase_24 AC 249 ms
66,496 KB
testcase_25 AC 233 ms
66,716 KB
testcase_26 AC 236 ms
67,064 KB
testcase_27 AC 241 ms
67,404 KB
testcase_28 AC 249 ms
67,204 KB
testcase_29 AC 249 ms
67,392 KB
testcase_30 AC 248 ms
66,512 KB
testcase_31 AC 243 ms
66,788 KB
testcase_32 AC 241 ms
66,768 KB
testcase_33 AC 250 ms
66,964 KB
testcase_34 AC 249 ms
67,256 KB
testcase_35 AC 250 ms
66,784 KB
testcase_36 AC 242 ms
66,424 KB
testcase_37 AC 222 ms
67,256 KB
testcase_38 AC 221 ms
67,528 KB
testcase_39 AC 218 ms
67,384 KB
testcase_40 AC 217 ms
67,544 KB
testcase_41 AC 216 ms
67,436 KB
testcase_42 AC 212 ms
67,608 KB
testcase_43 AC 217 ms
67,876 KB
testcase_44 AC 216 ms
67,528 KB
testcase_45 AC 218 ms
68,056 KB
testcase_46 AC 216 ms
67,260 KB
testcase_47 AC 216 ms
67,632 KB
testcase_48 AC 232 ms
67,932 KB
testcase_49 AC 215 ms
67,720 KB
testcase_50 AC 218 ms
67,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long[] c = new long[3];
		for (int i = 0; i < n; i++) {
			if (a[i] <= 2) {
				c[a[i]]++;
			}
		}
		c[0] = n - c[1] - c[2];

		long ans = 0;
		ans += c[0] * (c[0] - 1) / 2;
		ans += c[0] * c[1] * 2;
		ans += c[0] * c[2];
		ans += c[1] * (c[1] - 1) / 2 * 2;
		ans += c[1] * c[2] * 3;
		ans += c[2] * (c[2] - 1) / 2;
		System.out.println(ans);
	}
}
0