結果
| 問題 | 
                            No.1703 Much Matching
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tenten
                         | 
                    
| 提出日時 | 2021-11-09 15:11:59 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,876 bytes | 
| コンパイル時間 | 2,295 ms | 
| コンパイル使用メモリ | 77,796 KB | 
| 実行使用メモリ | 742,588 KB | 
| 最終ジャッジ日時 | 2024-11-18 14:23:07 | 
| 合計ジャッジ時間 | 10,549 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | WA * 3 RE * 31 MLE * 1 | 
ソースコード
import java.util.*;
import java.io.*;
public class Main {
    static int[][][] dp;
    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[n];
        fs = new int[m];
        for (int i = 0; i < q; i++) {
            ms[i] = sc.nextInt() - 1;
            fs[i] = sc.nextInt() - 1;
        }
        dp = new int[q][n][m];
        for (int[][] arr1 : dp) {
            for (int[] arr2 : arr1) {
                Arrays.fill(arr2, -1);
            }
        }
        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[q][n][m] < 0) {
            dp[q][n][m] = dfw(q - 1, n, m);
            if (ms[q] <= n && fs[q] <= m) {
                dp[q][n][m] = Math.max(dp[q][n][m], dfw(q - 1, ms[q] - 1, fs[q] - 1) + 1);
            }
        }
        return dp[q][n][m];
    }
}
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