結果
| 問題 |
No.1868 Teleporting Cyanmond
|
| コンテスト | |
| ユーザー |
kai4096_don
|
| 提出日時 | 2022-03-11 21:40:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 2,000 ms |
| コード長 | 1,058 bytes |
| コンパイル時間 | 3,706 ms |
| コンパイル使用メモリ | 235,564 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-16 01:51:03 |
| 合計ジャッジ時間 | 5,745 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#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;
}
kai4096_don