結果

問題 No.1470 Mex Sum
ユーザー tentententen
提出日時 2022-09-30 15:36:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 1,462 bytes
コンパイル時間 2,130 ms
コンパイル使用メモリ 74,556 KB
実行使用メモリ 56,252 KB
最終ジャッジ日時 2023-08-24 05:23:08
合計ジャッジ時間 12,671 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,292 KB
testcase_01 AC 44 ms
49,192 KB
testcase_02 AC 105 ms
51,924 KB
testcase_03 AC 102 ms
52,016 KB
testcase_04 AC 105 ms
51,764 KB
testcase_05 AC 102 ms
52,040 KB
testcase_06 AC 102 ms
52,080 KB
testcase_07 AC 96 ms
51,988 KB
testcase_08 AC 95 ms
51,912 KB
testcase_09 AC 107 ms
52,364 KB
testcase_10 AC 108 ms
52,276 KB
testcase_11 AC 102 ms
52,372 KB
testcase_12 AC 193 ms
55,488 KB
testcase_13 AC 220 ms
55,724 KB
testcase_14 AC 181 ms
55,372 KB
testcase_15 AC 195 ms
55,212 KB
testcase_16 AC 191 ms
55,168 KB
testcase_17 AC 192 ms
55,076 KB
testcase_18 AC 190 ms
55,260 KB
testcase_19 AC 198 ms
56,156 KB
testcase_20 AC 209 ms
55,472 KB
testcase_21 AC 194 ms
55,376 KB
testcase_22 AC 191 ms
55,276 KB
testcase_23 AC 216 ms
55,596 KB
testcase_24 AC 197 ms
55,548 KB
testcase_25 AC 192 ms
55,640 KB
testcase_26 AC 192 ms
55,484 KB
testcase_27 AC 192 ms
55,604 KB
testcase_28 AC 188 ms
55,184 KB
testcase_29 AC 200 ms
55,152 KB
testcase_30 AC 181 ms
56,096 KB
testcase_31 AC 194 ms
55,476 KB
testcase_32 AC 190 ms
55,428 KB
testcase_33 AC 203 ms
55,616 KB
testcase_34 AC 187 ms
55,164 KB
testcase_35 AC 193 ms
54,892 KB
testcase_36 AC 190 ms
55,072 KB
testcase_37 AC 175 ms
55,380 KB
testcase_38 AC 194 ms
55,764 KB
testcase_39 AC 180 ms
55,924 KB
testcase_40 AC 192 ms
55,728 KB
testcase_41 AC 199 ms
55,776 KB
testcase_42 AC 179 ms
55,440 KB
testcase_43 AC 177 ms
55,348 KB
testcase_44 AC 192 ms
55,816 KB
testcase_45 AC 189 ms
55,676 KB
testcase_46 AC 191 ms
55,668 KB
testcase_47 AC 200 ms
56,252 KB
testcase_48 AC 194 ms
55,696 KB
testcase_49 AC 193 ms
55,928 KB
testcase_50 AC 191 ms
55,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextInt();
        long one = 0;
        long two = 0;
        long three = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if (x == 1) {
                one++;
            } else if (x == 2) {
                two++;
            } else {
                three++;
            }
        }
        long oneone = one * (one - 1) / 2 + one * three;
        long onetwo = one * two;
        long others = n * (n - 1) / 2 - oneone - onetwo;
        System.out.println(oneone * 2 + onetwo * 3 + others);
    }
}
    
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0