結果

問題 No.1703 Much Matching
ユーザー tentententen
提出日時 2023-11-30 16:50:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 564 ms / 2,000 ms
コード長 2,037 bytes
コンパイル時間 3,137 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 64,932 KB
最終ジャッジ日時 2023-11-30 16:51:11
合計ジャッジ時間 16,112 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
53,980 KB
testcase_01 AC 56 ms
53,988 KB
testcase_02 AC 56 ms
53,988 KB
testcase_03 AC 69 ms
54,524 KB
testcase_04 AC 93 ms
55,132 KB
testcase_05 AC 80 ms
57,256 KB
testcase_06 AC 378 ms
62,528 KB
testcase_07 AC 146 ms
58,480 KB
testcase_08 AC 416 ms
62,620 KB
testcase_09 AC 429 ms
62,636 KB
testcase_10 AC 189 ms
58,956 KB
testcase_11 AC 223 ms
61,644 KB
testcase_12 AC 147 ms
58,504 KB
testcase_13 AC 270 ms
61,508 KB
testcase_14 AC 117 ms
55,812 KB
testcase_15 AC 231 ms
61,328 KB
testcase_16 AC 314 ms
62,508 KB
testcase_17 AC 326 ms
62,404 KB
testcase_18 AC 113 ms
55,672 KB
testcase_19 AC 441 ms
63,408 KB
testcase_20 AC 194 ms
60,428 KB
testcase_21 AC 473 ms
62,948 KB
testcase_22 AC 344 ms
62,668 KB
testcase_23 AC 299 ms
63,048 KB
testcase_24 AC 100 ms
55,532 KB
testcase_25 AC 149 ms
59,212 KB
testcase_26 AC 253 ms
62,376 KB
testcase_27 AC 339 ms
62,468 KB
testcase_28 AC 457 ms
62,664 KB
testcase_29 AC 240 ms
60,556 KB
testcase_30 AC 276 ms
62,604 KB
testcase_31 AC 148 ms
58,408 KB
testcase_32 AC 367 ms
62,580 KB
testcase_33 AC 315 ms
64,768 KB
testcase_34 AC 146 ms
58,512 KB
testcase_35 AC 183 ms
60,140 KB
testcase_36 AC 564 ms
64,932 KB
testcase_37 AC 101 ms
60,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int q = sc.nextInt();
        boolean[][] match = new boolean[n + 1][m + 1];
        while (q-- > 0) {
            match[sc.nextInt()][sc.nextInt()] = true;
        }
        int[][] dp = new int[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (match[i][j]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }
        System.out.println(dp[n][m]);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0