結果

問題 No.1703 Much Matching
ユーザー tentententen
提出日時 2024-01-11 16:55:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 530 ms / 2,000 ms
コード長 2,055 bytes
コンパイル時間 2,655 ms
コンパイル使用メモリ 94,816 KB
実行使用メモリ 64,996 KB
最終ジャッジ日時 2024-01-11 16:55:17
合計ジャッジ時間 15,426 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,988 KB
testcase_01 AC 52 ms
53,984 KB
testcase_02 AC 53 ms
53,976 KB
testcase_03 AC 80 ms
55,136 KB
testcase_04 AC 72 ms
54,512 KB
testcase_05 AC 76 ms
57,256 KB
testcase_06 AC 372 ms
62,528 KB
testcase_07 AC 139 ms
58,204 KB
testcase_08 AC 386 ms
62,636 KB
testcase_09 AC 394 ms
62,616 KB
testcase_10 AC 190 ms
59,008 KB
testcase_11 AC 227 ms
62,336 KB
testcase_12 AC 144 ms
58,500 KB
testcase_13 AC 268 ms
62,328 KB
testcase_14 AC 118 ms
55,912 KB
testcase_15 AC 213 ms
61,464 KB
testcase_16 AC 329 ms
62,504 KB
testcase_17 AC 318 ms
62,464 KB
testcase_18 AC 110 ms
55,652 KB
testcase_19 AC 426 ms
62,916 KB
testcase_20 AC 218 ms
60,624 KB
testcase_21 AC 438 ms
62,820 KB
testcase_22 AC 320 ms
62,676 KB
testcase_23 AC 288 ms
62,484 KB
testcase_24 AC 99 ms
55,536 KB
testcase_25 AC 147 ms
59,044 KB
testcase_26 AC 258 ms
62,416 KB
testcase_27 AC 333 ms
62,404 KB
testcase_28 AC 475 ms
62,616 KB
testcase_29 AC 231 ms
62,512 KB
testcase_30 AC 261 ms
61,744 KB
testcase_31 AC 142 ms
58,588 KB
testcase_32 AC 333 ms
62,556 KB
testcase_33 AC 301 ms
64,848 KB
testcase_34 AC 145 ms
58,652 KB
testcase_35 AC 181 ms
58,964 KB
testcase_36 AC 530 ms
64,996 KB
testcase_37 AC 99 ms
60,228 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[][] matches = new boolean[n + 1][m + 1];
        for (int i = 0; i < q; i++) {
            matches[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 (matches[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