結果

問題 No.2203 POWER!!!!!
ユーザー tentententen
提出日時 2024-04-30 15:33:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,586 bytes
コンパイル時間 2,503 ms
コンパイル使用メモリ 78,368 KB
実行使用メモリ 56,256 KB
最終ジャッジ日時 2024-04-30 15:33:51
合計ジャッジ時間 6,141 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
50,464 KB
testcase_01 AC 56 ms
50,376 KB
testcase_02 AC 57 ms
50,276 KB
testcase_03 AC 57 ms
50,416 KB
testcase_04 AC 54 ms
50,000 KB
testcase_05 AC 55 ms
49,944 KB
testcase_06 AC 56 ms
50,392 KB
testcase_07 AC 55 ms
50,256 KB
testcase_08 AC 113 ms
51,572 KB
testcase_09 AC 138 ms
54,624 KB
testcase_10 AC 166 ms
55,088 KB
testcase_11 AC 211 ms
56,064 KB
testcase_12 AC 109 ms
51,872 KB
testcase_13 AC 216 ms
56,200 KB
testcase_14 AC 217 ms
56,144 KB
testcase_15 AC 208 ms
56,224 KB
testcase_16 AC 214 ms
55,660 KB
testcase_17 AC 219 ms
56,256 KB
testcase_18 AC 55 ms
50,312 KB
testcase_19 AC 53 ms
50,424 KB
testcase_20 AC 54 ms
50,360 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[] counts = new int[9];
        while (n-- > 0) {
            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(int x, int p) {
        if (p == 0) {
            return 1;
        } else {
            return pow(x, p - 1) * x;
        }
    }
}
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