結果

問題 No.1703 Much Matching
コンテスト
ユーザー norioc
提出日時 2026-06-09 02:30:38
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 1,049 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,852 ms
コンパイル使用メモリ 213,652 KB
実行使用メモリ 26,624 KB
最終ジャッジ日時 2026-06-09 02:30:45
合計ジャッジ時間 5,181 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const ll INF = 1LL << 62;

int lis(const vector<int>& a) {
    int n = (int)a.size();

    vector<int> ranks(n);
    vector<ll> dp(n, INF);

    for (int i = 0; i < n; i++) {
        ranks[i] = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
        dp[ranks[i]] = a[i];
    }

    return *max_element(ranks.begin(), ranks.end()) + 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M, Q;
    cin >> N >> M >> Q;

    vector<pair<int, int>> xs;
    xs.reserve(Q);

    for (int i = 0; i < Q; i++) {
        int A, B;
        cin >> A >> B;
        --A;
        --B;
        xs.emplace_back(A, B);
    }

    sort(xs.begin(), xs.end(), [](const auto& lhs, const auto& rhs) {
        if (lhs.first != rhs.first) return lhs.first < rhs.first;
        return lhs.second > rhs.second;
    });

    vector<int> seq;
    seq.reserve(Q);

    for (auto [a, b] : xs) {
        seq.push_back(b);
    }

    cout << lis(seq) << '\n';

    return 0;
}
0