結果
| 問題 | No.2709 1975 Powers |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-04-01 16:03:40 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,518 bytes |
| 記録 | |
| コンパイル時間 | 2,179 ms |
| コンパイル使用メモリ | 78,756 KB |
| 実行使用メモリ | 744,832 KB |
| 最終ジャッジ日時 | 2024-09-30 21:52:57 |
| 合計ジャッジ時間 | 8,104 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 MLE * 1 -- * 22 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
static int[][] values;
static int[] base = new int[]{10, 9, 7, 5};
static int[][][] dp;
static int p;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
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);
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]);
}
}
dp = new int[n][p][4];
for (int[][] arr1 : dp) {
for (int[] arr2 : arr1) {
Arrays.fill(arr2, -1);
}
}
System.out.println(dfw(n - 1, (p - q) % p, 3));
}
static int dfw(int idx, int v, int w) {
if (w < 0) {
if (v == 0) {
return 1;
} else {
return 0;
}
}
if (idx < 0) {
return 0;
}
if (dp[idx][v][w] < 0) {
dp[idx][v][w] = dfw(idx - 1, v, w) + dfw(idx - 1, (v + values[idx][w]) % p, w - 1);
}
return dp[idx][v][w];
}
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();
}
}
}
tenten