結果

問題 No.2203 POWER!!!!!
ユーザー tentententen
提出日時 2023-02-10 16:05:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,939 bytes
コンパイル時間 2,513 ms
コンパイル使用メモリ 86,260 KB
実行使用メモリ 56,384 KB
最終ジャッジ日時 2023-09-21 18:45:11
合計ジャッジ時間 6,560 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,392 KB
testcase_01 AC 44 ms
49,232 KB
testcase_02 AC 43 ms
49,236 KB
testcase_03 AC 44 ms
49,444 KB
testcase_04 AC 44 ms
49,288 KB
testcase_05 AC 44 ms
49,364 KB
testcase_06 AC 45 ms
49,384 KB
testcase_07 AC 44 ms
49,400 KB
testcase_08 AC 95 ms
52,236 KB
testcase_09 AC 130 ms
55,316 KB
testcase_10 AC 167 ms
56,120 KB
testcase_11 AC 182 ms
55,936 KB
testcase_12 AC 94 ms
51,968 KB
testcase_13 AC 190 ms
55,732 KB
testcase_14 AC 192 ms
56,052 KB
testcase_15 AC 189 ms
56,384 KB
testcase_16 AC 188 ms
56,040 KB
testcase_17 AC 188 ms
55,848 KB
testcase_18 AC 45 ms
49,156 KB
testcase_19 AC 44 ms
49,464 KB
testcase_20 AC 43 ms
49,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] counts = new int[9];
        for (int i = 0; i < n; i++) {
            counts[sc.nextInt()]++;
        }
        long ans = 0;
        for (int i = 1; i <= 8; i++) {
            for (int j = 1; j <= 8; j++) {
                ans += pow(i, j) * counts[i] * counts[j];
            }
        }
        System.out.println(ans);
    }
    
    static long pow(long x, int p) {
        if (p == 0) {
            return 1;
        } else {
            return x * pow(x, p - 1);
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0