結果

問題 No.2796 Small Matryoshka
コンテスト
ユーザー tnakao0123
提出日時 2024-07-03 14:17:00
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 801 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 328 ms
コンパイル使用メモリ 77,144 KB
実行使用メモリ 16,476 KB
最終ジャッジ日時 2026-07-05 02:37:08
合計ジャッジ時間 1,941 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 2796.cc:  No.2796 Small Matryoshka - yukicoder
 */

#include<cstdio>
#include<set>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

using msi = multiset<int>;
using pii = pair<int,int>;

/* global variables */

int irs[MAX_N], ors[MAX_N];
pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", irs + i, ors + i);

  for (int i = 0; i < n; i++) ps[i] = {ors[i], irs[i]};
  sort(ps, ps + n);

  msi rs;
  for (int i = 0; i < n; i++) {
    auto [ori, iri] = ps[i];
    auto sit = rs.upper_bound(iri);
    if (sit != rs.begin()) rs.erase(--sit);
    rs.insert(ori);
  }

  printf("%d\n", (int)rs.size() - 1);
  
  return 0;
}
0