結果

問題 No.1470 Mex Sum
ユーザー tentententen
提出日時 2024-04-23 17:07:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,617 bytes
コンパイル時間 2,647 ms
コンパイル使用メモリ 78,860 KB
実行使用メモリ 56,296 KB
最終ジャッジ日時 2024-04-23 17:07:55
合計ジャッジ時間 12,645 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
50,324 KB
testcase_01 AC 47 ms
50,216 KB
testcase_02 AC 97 ms
51,792 KB
testcase_03 AC 103 ms
51,716 KB
testcase_04 AC 95 ms
52,128 KB
testcase_05 AC 93 ms
51,956 KB
testcase_06 AC 102 ms
52,036 KB
testcase_07 AC 100 ms
51,804 KB
testcase_08 AC 101 ms
51,832 KB
testcase_09 AC 106 ms
52,064 KB
testcase_10 AC 104 ms
51,976 KB
testcase_11 AC 132 ms
52,092 KB
testcase_12 AC 190 ms
55,484 KB
testcase_13 AC 180 ms
55,536 KB
testcase_14 AC 194 ms
55,624 KB
testcase_15 AC 190 ms
55,448 KB
testcase_16 AC 195 ms
55,412 KB
testcase_17 AC 213 ms
55,532 KB
testcase_18 AC 175 ms
55,804 KB
testcase_19 AC 186 ms
55,536 KB
testcase_20 AC 187 ms
55,656 KB
testcase_21 AC 188 ms
55,536 KB
testcase_22 AC 181 ms
55,752 KB
testcase_23 AC 202 ms
55,520 KB
testcase_24 AC 190 ms
55,828 KB
testcase_25 AC 188 ms
55,780 KB
testcase_26 AC 183 ms
55,464 KB
testcase_27 AC 190 ms
55,604 KB
testcase_28 AC 177 ms
55,588 KB
testcase_29 AC 187 ms
55,568 KB
testcase_30 AC 196 ms
55,544 KB
testcase_31 AC 201 ms
55,404 KB
testcase_32 AC 199 ms
55,692 KB
testcase_33 AC 192 ms
55,736 KB
testcase_34 AC 192 ms
55,704 KB
testcase_35 AC 210 ms
55,316 KB
testcase_36 AC 199 ms
55,664 KB
testcase_37 AC 203 ms
56,088 KB
testcase_38 AC 187 ms
56,276 KB
testcase_39 AC 181 ms
55,804 KB
testcase_40 AC 195 ms
56,296 KB
testcase_41 AC 213 ms
56,100 KB
testcase_42 AC 196 ms
56,096 KB
testcase_43 AC 197 ms
56,200 KB
testcase_44 AC 194 ms
56,004 KB
testcase_45 AC 199 ms
55,692 KB
testcase_46 AC 170 ms
55,760 KB
testcase_47 AC 189 ms
55,600 KB
testcase_48 AC 185 ms
56,276 KB
testcase_49 AC 191 ms
56,028 KB
testcase_50 AC 195 ms
55,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

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