結果

問題 No.2796 Small Matryoshka
ユーザー haihamabossuhaihamabossu
提出日時 2024-06-28 21:52:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 430 ms / 2,000 ms
コード長 826 bytes
コンパイル時間 2,423 ms
コンパイル使用メモリ 218,576 KB
実行使用メモリ 43,648 KB
最終ジャッジ日時 2024-06-28 21:52:19
合計ジャッジ時間 6,677 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 43 ms
9,472 KB
testcase_06 AC 366 ms
38,912 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 269 ms
30,976 KB
testcase_09 AC 246 ms
21,760 KB
testcase_10 AC 430 ms
43,648 KB
testcase_11 AC 411 ms
41,856 KB
testcase_12 AC 65 ms
9,088 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 54 ms
8,448 KB
testcase_15 AC 14 ms
5,376 KB
testcase_16 AC 24 ms
5,888 KB
testcase_17 AC 318 ms
28,032 KB
testcase_18 AC 352 ms
31,488 KB
testcase_19 AC 83 ms
12,160 KB
testcase_20 AC 122 ms
15,488 KB
testcase_21 AC 295 ms
27,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll INF = 1e18;
void solve() {
  ll n;
  cin >> n;
  set<ll> st;
  st.insert(INF);
  map<ll, set<pair<ll, ll>>> mp;
  rep(i, n) {
    ll l, r;
    cin >> l >> r;
    st.insert(l);
    mp[l].emplace(r, i);
  }
  ll ans = 0;
  while (st.size() > 1) {
    ans++;
    ll now = 0;
    for (;;) {
      ll nex = *st.lower_bound(now);
      if (nex == INF)
        break;
      auto iter = mp[nex].begin();
      now = iter->first;
      mp[nex].erase(iter);
      if (mp[nex].size() == 0)
        st.erase(nex);
    }
  }
  ans--;
  cout << ans << '\n';
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
0