結果

問題 No.1868 Teleporting Cyanmond
ユーザー kai4096_donkai4096_don
提出日時 2022-03-11 21:40:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,058 bytes
コンパイル時間 3,917 ms
コンパイル使用メモリ 233,220 KB
実行使用メモリ 6,492 KB
最終ジャッジ日時 2023-10-14 06:37:42
合計ジャッジ時間 6,076 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 24 ms
4,352 KB
testcase_04 AC 19 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 5 ms
4,352 KB
testcase_07 AC 13 ms
4,352 KB
testcase_08 AC 9 ms
4,356 KB
testcase_09 AC 11 ms
4,352 KB
testcase_10 AC 23 ms
4,348 KB
testcase_11 AC 2 ms
4,356 KB
testcase_12 AC 7 ms
4,352 KB
testcase_13 AC 15 ms
4,356 KB
testcase_14 AC 30 ms
4,352 KB
testcase_15 AC 21 ms
4,356 KB
testcase_16 AC 4 ms
4,368 KB
testcase_17 AC 7 ms
4,356 KB
testcase_18 AC 49 ms
4,532 KB
testcase_19 AC 47 ms
4,372 KB
testcase_20 AC 50 ms
4,432 KB
testcase_21 AC 50 ms
4,368 KB
testcase_22 AC 49 ms
4,348 KB
testcase_23 AC 71 ms
6,408 KB
testcase_24 AC 70 ms
6,464 KB
testcase_25 AC 73 ms
6,492 KB
testcase_26 AC 70 ms
6,392 KB
testcase_27 AC 72 ms
6,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//const long nPrime = 1000000007;
//const long nPrime = 998244353;
typedef long long ll;
int main() {
    ll n;
    cin >> n;
    map<ll, ll> miAns;
    miAns.insert(make_pair(1,0));
    for(ll i = 0; i < n-1; i++){
        ll x;
        cin >> x;
        auto itr = miAns.lower_bound(i+1);
        ll k = itr->second+1;
        auto itr2 = miAns.lower_bound(x);
        if(itr2 == miAns.end() || itr2->second > k){
            if(itr2->first == x){
                miAns.erase(itr2);
            }
            miAns.insert(make_pair(x,k));
            auto itr3 = miAns.find(x);
            if(itr3 != miAns.begin()){
                itr3--;
                while(itr3->second >= k){
                    miAns.erase(itr3++);
                    if(itr3 == miAns.begin()){
                        break;
                    }
                    itr3--;
                }
            }
        }
    }
    
    cout << miAns.find(n)->second <<endl;
    return 0;
}
0