結果

問題 No.1703 Much Matching
ユーザー tentententen
提出日時 2021-11-29 17:23:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,634 ms / 2,000 ms
コード長 1,685 bytes
コンパイル時間 3,397 ms
コンパイル使用メモリ 75,468 KB
実行使用メモリ 148,608 KB
最終ジャッジ日時 2023-09-15 08:47:43
合計ジャッジ時間 24,675 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,372 KB
testcase_01 AC 45 ms
49,228 KB
testcase_02 AC 42 ms
49,320 KB
testcase_03 AC 114 ms
55,456 KB
testcase_04 AC 114 ms
55,716 KB
testcase_05 AC 135 ms
58,000 KB
testcase_06 AC 835 ms
82,504 KB
testcase_07 AC 169 ms
55,252 KB
testcase_08 AC 886 ms
88,696 KB
testcase_09 AC 783 ms
89,348 KB
testcase_10 AC 268 ms
60,648 KB
testcase_11 AC 353 ms
63,788 KB
testcase_12 AC 168 ms
55,252 KB
testcase_13 AC 417 ms
66,464 KB
testcase_14 AC 127 ms
52,716 KB
testcase_15 AC 392 ms
62,076 KB
testcase_16 AC 505 ms
70,560 KB
testcase_17 AC 582 ms
74,428 KB
testcase_18 AC 119 ms
52,272 KB
testcase_19 AC 945 ms
92,808 KB
testcase_20 AC 249 ms
60,172 KB
testcase_21 AC 1,050 ms
100,912 KB
testcase_22 AC 664 ms
76,208 KB
testcase_23 AC 489 ms
69,032 KB
testcase_24 AC 114 ms
51,772 KB
testcase_25 AC 193 ms
55,780 KB
testcase_26 AC 441 ms
65,780 KB
testcase_27 AC 597 ms
76,508 KB
testcase_28 AC 1,032 ms
99,320 KB
testcase_29 AC 380 ms
67,776 KB
testcase_30 AC 422 ms
65,612 KB
testcase_31 AC 191 ms
55,876 KB
testcase_32 AC 660 ms
77,636 KB
testcase_33 AC 535 ms
73,748 KB
testcase_34 AC 175 ms
55,432 KB
testcase_35 AC 264 ms
60,652 KB
testcase_36 AC 1,634 ms
148,608 KB
testcase_37 AC 139 ms
60,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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();
        HashMap<Integer, HashSet<Integer>> pairs = new HashMap<>();
        for (int i = 0; i < q; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (!pairs.containsKey(a)) {
                pairs.put(a, new HashSet<>());
            }
            pairs.get(a).add(b);
        }
        int[][] dp = new int[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (pairs.containsKey(i) && pairs.get(i).contains(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 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 next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0