結果

問題 No.1470 Mex Sum
ユーザー tentententen
提出日時 2022-08-05 09:06:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 1,472 bytes
コンパイル時間 2,610 ms
コンパイル使用メモリ 73,956 KB
実行使用メモリ 56,224 KB
最終ジャッジ日時 2023-10-13 07:27:32
合計ジャッジ時間 16,939 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,220 KB
testcase_01 AC 47 ms
49,652 KB
testcase_02 AC 88 ms
52,280 KB
testcase_03 AC 99 ms
52,168 KB
testcase_04 AC 103 ms
52,236 KB
testcase_05 AC 94 ms
52,108 KB
testcase_06 AC 99 ms
52,092 KB
testcase_07 AC 102 ms
52,140 KB
testcase_08 AC 105 ms
51,892 KB
testcase_09 AC 91 ms
52,236 KB
testcase_10 AC 104 ms
52,208 KB
testcase_11 AC 102 ms
52,448 KB
testcase_12 AC 192 ms
55,636 KB
testcase_13 AC 213 ms
55,616 KB
testcase_14 AC 193 ms
55,256 KB
testcase_15 AC 190 ms
55,424 KB
testcase_16 AC 190 ms
55,488 KB
testcase_17 AC 184 ms
55,532 KB
testcase_18 AC 184 ms
55,308 KB
testcase_19 AC 190 ms
55,428 KB
testcase_20 AC 186 ms
55,348 KB
testcase_21 AC 203 ms
55,644 KB
testcase_22 AC 199 ms
55,812 KB
testcase_23 AC 190 ms
55,644 KB
testcase_24 AC 192 ms
55,548 KB
testcase_25 AC 191 ms
55,856 KB
testcase_26 AC 215 ms
55,568 KB
testcase_27 AC 187 ms
55,352 KB
testcase_28 AC 196 ms
55,576 KB
testcase_29 AC 190 ms
55,076 KB
testcase_30 AC 194 ms
55,440 KB
testcase_31 AC 203 ms
55,944 KB
testcase_32 AC 187 ms
55,836 KB
testcase_33 AC 217 ms
56,160 KB
testcase_34 AC 196 ms
55,444 KB
testcase_35 AC 198 ms
53,472 KB
testcase_36 AC 198 ms
54,144 KB
testcase_37 AC 191 ms
56,200 KB
testcase_38 AC 189 ms
56,180 KB
testcase_39 AC 195 ms
55,900 KB
testcase_40 AC 194 ms
55,644 KB
testcase_41 AC 190 ms
55,984 KB
testcase_42 AC 197 ms
55,956 KB
testcase_43 AC 191 ms
55,756 KB
testcase_44 AC 190 ms
55,904 KB
testcase_45 AC 192 ms
55,612 KB
testcase_46 AC 194 ms
56,224 KB
testcase_47 AC 193 ms
56,012 KB
testcase_48 AC 189 ms
53,800 KB
testcase_49 AC 185 ms
56,012 KB
testcase_50 AC 172 ms
55,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long one = 0;
        long two = 0;
        long other = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if (x == 1) {
                one++;
            } else if (x == 2) {
                two++;
            } else {
                other++;
            }
        }
        long ans = 0;
        ans += 2 * one * (one - 1) / 2;
        ans += 3 * one * two;
        ans += 2 * one * other;
        ans += 1 * two * (two - 1) / 2;
        ans += 1 * two * other;
        ans += 1 * other * (other - 1) / 2;
        System.out.println(ans);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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