結果

問題 No.1703 Much Matching
ユーザー phsplsphspls
提出日時 2022-10-02 20:16:55
言語 Rust
(1.77.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 143,688 KB
実行使用メモリ 26,172 KB
最終ジャッジ日時 2023-08-26 17:56:41
合計ジャッジ時間 3,516 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 8 ms
6,664 KB
testcase_06 AC 50 ms
9,540 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 56 ms
12,928 KB
testcase_09 AC 60 ms
11,812 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 17 ms
6,152 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 26 ms
6,412 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 18 ms
7,964 KB
testcase_16 AC 32 ms
6,312 KB
testcase_17 AC 36 ms
7,312 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 76 ms
12,904 KB
testcase_20 AC 10 ms
4,376 KB
testcase_21 AC 91 ms
15,152 KB
testcase_22 AC 42 ms
10,576 KB
testcase_23 AC 31 ms
7,172 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 24 ms
8,780 KB
testcase_27 AC 43 ms
7,700 KB
testcase_28 AC 79 ms
15,764 KB
testcase_29 AC 18 ms
6,960 KB
testcase_30 AC 24 ms
7,212 KB
testcase_31 AC 5 ms
4,376 KB
testcase_32 AC 43 ms
10,100 KB
testcase_33 AC 32 ms
10,104 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 10 ms
4,380 KB
testcase_36 AC 168 ms
26,172 KB
testcase_37 AC 14 ms
10,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut nmq = String::new();
    std::io::stdin().read_line(&mut nmq).ok();
    let nmq: Vec<usize> = nmq.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nmq[0];
    let m = nmq[1];
    let q = nmq[2];
    let queries = (0..q).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
            (temp[0]-1, temp[1]-1)
        })
        .collect::<Vec<_>>();

    let mut relations = vec![vec![false; m]; n];
    for &(a, b) in queries.iter() {
        relations[a][b] = true;
    }
    let mut dp = vec![vec![0usize; m+1]; n+1];
    for i in 0..=n {
        for j in 0..=m {
            if i+1 <= n {
                dp[i+1][j] = dp[i+1][j].max(dp[i][j]);
            }
            if j+1 <= m {
                dp[i][j+1] = dp[i][j+1].max(dp[i][j]);
            }
            if i+1 <= n && j+1 <= m {
                dp[i+1][j+1] = dp[i+1][j+1].max(dp[i][j] + if relations[i][j] { 1 } else { 0 });
            }
        }
    }
    println!("{}", dp[n][m]);
}
0