結果

問題 No.2709 1975 Powers
ユーザー tentententen
提出日時 2024-04-01 16:08:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 440 ms / 2,000 ms
コード長 2,473 bytes
コンパイル時間 3,804 ms
コンパイル使用メモリ 78,768 KB
実行使用メモリ 55,808 KB
最終ジャッジ日時 2024-04-01 16:08:57
合計ジャッジ時間 8,847 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
54,068 KB
testcase_01 AC 55 ms
53,984 KB
testcase_02 AC 65 ms
54,368 KB
testcase_03 AC 213 ms
55,780 KB
testcase_04 AC 301 ms
55,808 KB
testcase_05 AC 303 ms
55,524 KB
testcase_06 AC 156 ms
55,516 KB
testcase_07 AC 60 ms
54,000 KB
testcase_08 AC 138 ms
55,404 KB
testcase_09 AC 284 ms
55,428 KB
testcase_10 AC 53 ms
53,992 KB
testcase_11 AC 87 ms
55,148 KB
testcase_12 AC 123 ms
55,412 KB
testcase_13 AC 292 ms
55,404 KB
testcase_14 AC 108 ms
55,716 KB
testcase_15 AC 117 ms
55,424 KB
testcase_16 AC 238 ms
55,424 KB
testcase_17 AC 55 ms
54,120 KB
testcase_18 AC 101 ms
55,520 KB
testcase_19 AC 376 ms
55,524 KB
testcase_20 AC 67 ms
54,372 KB
testcase_21 AC 138 ms
55,412 KB
testcase_22 AC 336 ms
55,792 KB
testcase_23 AC 437 ms
55,420 KB
testcase_24 AC 440 ms
55,412 KB
testcase_25 AC 336 ms
53,836 KB
testcase_26 AC 335 ms
55,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int p;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] base = new int[]{10, 9, 7, 5};
        p = sc.nextInt();
        int q = sc.nextInt();
        int[] tmp = new int[n];
        for (int i = 0; i < n; i++) {
            tmp[i] = sc.nextInt();
        }
        Arrays.sort(tmp);
        int[][] values = new int[n][4];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 4; j++) {
                values[i][j] = pow(base[j], tmp[i]);
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int current1 = values[i][0];
            for (int j = i + 1; j < n; j++) {
                int current2 = (current1 + values[j][1]) % p;
                for (int k = j + 1; k < n; k++) {
                    int current3 = (current2 + values[k][2]) % p;
                    for (int l = k + 1; l < n; l++) {
                        int current4 = (current3 + values[l][3]) % p;
                        if (current4 == q) {
                            ans++;
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }

    static int pow(int x, int pp) {
        if (pp == 0) {
            return 1;
        } else if (pp % 2 == 0) {
            return pow((int)((long)x * x % p), pp / 2);
        } else {
            return (int)((long)pow(x, pp - 1) * x % p);
        }
    }
}
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