結果

問題 No.1470 Mex Sum
ユーザー tentententen
提出日時 2021-04-13 12:53:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,302 bytes
コンパイル時間 2,668 ms
コンパイル使用メモリ 74,120 KB
実行使用メモリ 56,284 KB
最終ジャッジ日時 2023-09-12 00:25:49
合計ジャッジ時間 13,639 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,384 KB
testcase_01 AC 44 ms
49,408 KB
testcase_02 AC 98 ms
52,348 KB
testcase_03 AC 103 ms
52,264 KB
testcase_04 AC 101 ms
52,404 KB
testcase_05 AC 101 ms
52,248 KB
testcase_06 AC 104 ms
52,112 KB
testcase_07 AC 99 ms
52,336 KB
testcase_08 AC 103 ms
52,264 KB
testcase_09 AC 101 ms
52,024 KB
testcase_10 AC 95 ms
52,396 KB
testcase_11 AC 108 ms
52,468 KB
testcase_12 AC 192 ms
55,228 KB
testcase_13 AC 201 ms
55,456 KB
testcase_14 AC 188 ms
55,504 KB
testcase_15 AC 198 ms
55,272 KB
testcase_16 AC 192 ms
55,140 KB
testcase_17 AC 196 ms
55,548 KB
testcase_18 AC 190 ms
55,196 KB
testcase_19 AC 188 ms
55,344 KB
testcase_20 AC 201 ms
55,380 KB
testcase_21 AC 201 ms
55,300 KB
testcase_22 AC 200 ms
55,444 KB
testcase_23 AC 194 ms
55,464 KB
testcase_24 AC 218 ms
55,256 KB
testcase_25 AC 200 ms
55,388 KB
testcase_26 AC 219 ms
55,596 KB
testcase_27 AC 203 ms
55,524 KB
testcase_28 AC 190 ms
55,196 KB
testcase_29 AC 205 ms
55,272 KB
testcase_30 AC 203 ms
55,468 KB
testcase_31 AC 198 ms
55,360 KB
testcase_32 AC 195 ms
55,424 KB
testcase_33 AC 200 ms
55,384 KB
testcase_34 AC 214 ms
55,228 KB
testcase_35 AC 217 ms
55,176 KB
testcase_36 AC 217 ms
55,336 KB
testcase_37 AC 189 ms
55,916 KB
testcase_38 AC 177 ms
55,704 KB
testcase_39 AC 188 ms
56,072 KB
testcase_40 AC 173 ms
55,848 KB
testcase_41 AC 177 ms
55,716 KB
testcase_42 AC 190 ms
56,284 KB
testcase_43 AC 201 ms
55,972 KB
testcase_44 AC 198 ms
55,588 KB
testcase_45 AC 194 ms
55,980 KB
testcase_46 AC 189 ms
55,772 KB
testcase_47 AC 173 ms
55,700 KB
testcase_48 AC 188 ms
55,848 KB
testcase_49 AC 179 ms
55,716 KB
testcase_50 AC 182 ms
55,768 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 a = sc.nextInt();
            if (a == 1) {
                one++;
            } else if (a == 2) {
                two++;
            } else {
                other++;
            }
        }
        long ans = 0;
        ans += one * (one - 1) / 2 * 2;
        ans += one * two * 3;
        ans += one * other * 2;
        ans += (two + other - 1) * (two + other) / 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 String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0