結果

問題 No.1703 Much Matching
ユーザー batsumaru
提出日時 2021-10-08 23:01:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 706 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 1,761 ms
コンパイル使用メモリ 174,584 KB
実行使用メモリ 34,496 KB
最終ジャッジ日時 2024-07-23 06:22:27
合計ジャッジ時間 6,871 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, m, q;
  cin >> n >> m >> q;
  vector<ll> a(q), b(q);
  REP(i, q) { cin >> a[i] >> b[i]; }
  vector<ll> ord(q);
  iota(ALL(ord), 0);
  sort(ALL(ord), [&](ll i, ll j) {
    if (a[i] == a[j]) {
      return b[i] > b[j];
    }
    return a[i] < a[j];
  });

  const ll INF = 1e18;
  vector<ll> dp(q + 1, INF);
  dp[0] = -1;
  REP(ii, q) {
    ll i = ord[ii];
    ll v = b[i];
    auto it = upper_bound(ALL(dp), v);
    ll idx = it - dp.begin();
    if (dp[idx - 1] != v) {
      *it = v;
    }
  }

  ll ans = 0;
  REP(i, q + 1) {
    if (dp[i] != INF) {
      ans = max(ans, i);
    }
  }
  cout << ans << endl;
}
0