結果
| 問題 | No.1703 Much Matching |
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 14:50:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,687 bytes |
| 記録 | |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 82,792 KB |
| 実行使用メモリ | 150,940 KB |
| 最終ジャッジ日時 | 2025-06-12 14:54:26 |
| 合計ジャッジ時間 | 23,399 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 TLE * 2 -- * 1 |
ソースコード
n, m, q = map(int, input().split())
pairs = []
for _ in range(q):
a, b = map(int, input().split())
pairs.append((a, b))
pairs.sort(key=lambda x: (x[0], x[1]))
class BIT:
def __init__(self, size):
self.size = size
self.tree = [0] * (self.size + 1) # 1-based indexing
def update(self, idx, value):
while idx <= self.size:
if self.tree[idx] < value:
self.tree[idx] = value
else:
break
idx += idx & -idx
def query(self, idx):
res = 0
while idx > 0:
if self.tree[idx] > res:
res = self.tree[idx]
idx -= idx & -idx
return res
bit = BIT(m)
max_dp = 0
current_a = None
group = []
for a, b in pairs:
if a != current_a:
if group:
temp_dp = []
for (a_p, b_p) in group:
max_val = bit.query(b_p - 1)
current_dp = max_val + 1
temp_dp.append((b_p, current_dp))
if current_dp > max_dp:
max_dp = current_dp
for (b_p, current_dp) in temp_dp:
if current_dp > bit.query(b_p):
bit.update(b_p, current_dp)
current_a = a
group = [(a, b)]
else:
group.append((a, b))
if group:
temp_dp = []
for (a_p, b_p) in group:
max_val = bit.query(b_p - 1)
current_dp = max_val + 1
temp_dp.append((b_p, current_dp))
if current_dp > max_dp:
max_dp = current_dp
for (b_p, current_dp) in temp_dp:
if current_dp > bit.query(b_p):
bit.update(b_p, current_dp)
print(max_dp)
gew1fw