結果
| 問題 |
No.1703 Much Matching
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-09 15:22:03 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,938 bytes |
| コンパイル時間 | 2,110 ms |
| コンパイル使用メモリ | 79,372 KB |
| 実行使用メモリ | 889,920 KB |
| 最終ジャッジ日時 | 2024-11-18 14:40:15 |
| 合計ジャッジ時間 | 121,585 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 MLE * 1 |
| other | WA * 2 TLE * 30 MLE * 3 |
ソースコード
import java.util.*;
import java.io.*;
public class Main {
static ArrayList<HashMap<Integer, HashMap<Integer, Integer>>> dp = new ArrayList<>();
static int[] ms;
static int[] fs;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int m = sc.nextInt();
int q = sc.nextInt();
ms = new int[q];
fs = new int[q];
for (int i = 0; i < q; i++) {
ms[i] = sc.nextInt() - 1;
fs[i] = sc.nextInt() - 1;
dp.add(new HashMap<>());
}
System.out.println(dfw(q - 1, n - 1, m - 1));
}
static int dfw(int q, int n, int m) {
if (q < 0 || n < 0 || m < 0) {
return 0;
}
if (dp.get(q).containsKey(n)) {
if (dp.get(q).get(n).containsKey(m)) {
return dp.get(q).get(n).get(m);
}
} else {
dp.get(q).put(n, new HashMap<>());
}
int ans = dfw(q - 1, n, m);
ans = Math.max(ans, dfw(q - 1, ms[q] - 1, fs[q] - 1) + 1);
dp.get(q).get(n).put(m, ans);
return ans;
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
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 String nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten