結果

問題 No.1470 Mex Sum
ユーザー ks2m
提出日時 2021-04-09 21:29:46
言語 Java
(openjdk 23)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 3,424 ms
コンパイル使用メモリ 77,196 KB
実行使用メモリ 66,876 KB
最終ジャッジ日時 2024-06-25 04:14:09
合計ジャッジ時間 16,094 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

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