結果

問題 No.1703 Much Matching
ユーザー ks2mks2m
提出日時 2021-10-08 22:42:13
言語 Java
(openjdk 23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,131 bytes
コンパイル時間 2,393 ms
コンパイル使用メモリ 80,628 KB
実行使用メモリ 95,008 KB
最終ジャッジ日時 2024-07-23 05:48:05
合計ジャッジ時間 24,849 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int q = Integer.parseInt(sa[2]);
		Obj[] arr = new Obj[q];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			Obj o = new Obj();
			o.a = Integer.parseInt(sa[0]);
			o.b = Integer.parseInt(sa[1]);
			arr[i] = o;
		}
		br.close();

		Arrays.sort(arr, (o1, o2) -> {
			if (o1.a != o2.a) {
				return o1.a - o2.a;
			}
			return o2.b - o1.b;
		});

		int[] dp = new int[m + 1];
		for (int i = 1; i <= m; i++) {
			dp[i] = Integer.MAX_VALUE;
		}

		for (int i = 0; i < q; i++) {
			int idx = Arrays.binarySearch(dp, arr[i].b);
			if (idx < 0) idx = ~idx;
			dp[idx] = arr[i].b;
		}

		int lis = Arrays.binarySearch(dp, Integer.MAX_VALUE - 1);
		if (lis < 0) {
			lis = ~lis;
			lis--;
		}
		System.out.println(lis);
	}

	static class Obj {
		int a, b;
	}
}
0