結果

問題 No.2796 Small Matryoshka
ユーザー Shreyan RayShreyan Ray
提出日時 2024-06-28 22:33:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,645 bytes
コンパイル時間 2,408 ms
コンパイル使用メモリ 210,868 KB
実行使用メモリ 9,604 KB
最終ジャッジ日時 2024-06-28 22:33:40
合計ジャッジ時間 3,453 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 12 ms
6,940 KB
testcase_06 AC 67 ms
8,704 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 55 ms
7,424 KB
testcase_09 AC 60 ms
9,460 KB
testcase_10 AC 61 ms
9,472 KB
testcase_11 AC 60 ms
9,604 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void Solve() 
{
    int n; cin >> n;
    
    vector <pair<int, int>> a(n);
    for (auto &x : a){
        cin >> x.second >> x.first;
    }
    
    sort(a.begin(), a.end());
    vector <int> dp(n, 0);
    vector <int> pdp(n, 0);
    int ans = 0;
    for (int i = 0; i < n; i++){
        // find how good x.second is 
        if (a[i].second < a[0].first){
            ans += 1;
            dp[i] = 1;
            pdp[i] = 1;
            if (i != 0) pdp[i] = max(pdp[i], pdp[i - 1]);
            continue;
        }
        
        int l = 0, r = n;
        while (l != r){
            int mid = (l + r + 1) / 2;
            
            if (a[i].second >= a[mid].first){
                l = mid;
            } else {
                r = mid - 1;
            }
        }
        
        dp[i] = 1 + pdp[l];
        pdp[i] = max(pdp[i - 1], dp[i]);
    }
    
    ans -= 1;
    
    cout << ans << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // freopen("in",  "r", stdin);
    // freopen("out", "w", stdout);
    
  //  cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
0