# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1046178 | Zicrus | Teleporters (IOI08_teleporters) | C++17 | 1064 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m;
vector<ll> a, r;
vector<bool> vst;
ll r1 = 0;
void simulateVst(vector<ll> &a) {
ll res = 0;
ll i = 0;
while (i < a.size()) {
r[i] = res;
i = a[i];
vst[i] = true;
i++;
res++;
}
r1 = res;
}
ll simulateRange(vector<ll> &a, ll start) {
ll res = r[start]+1;
ll i = start+1;
while (i != a[start]+1) {
i = a[i];
if (i == start) {
i--;
res++;
}
i++;
res++;
}
return res + (i < r.size() ? r1 - r[i] : 0);
}
ll simulate(vector<ll> &a) {
ll res = 0;
ll i = 0;
while (i < a.size()) {
i = a[i];
i++;
res++;
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin >> n >> m;
vector<pair<ll, ll>> tp;
for (int i = 0; i < n; i++) {
ll x, y;
cin >> x >> y;
tp.push_back({x, y});
tp.push_back({y, x});
}
sort(tp.begin(), tp.end());
unordered_map<ll, ll> ids;
for (int i = 0; i < 2*n; i++) {
ids[tp[i].first] = i;
}
a = vector<ll>(2*n);
for (int i = 0; i < 2*n; i++) {
a[i] = ids[tp[i].second];
}
ll mx = m == 0 ? simulate(a) : 0;
while (m--) {
vst = vector<bool>(a.size());
r = vector<ll>(a.size());
simulateVst(a);
ll mxA = -1;
mx = r1+1;
for (int i = 0; i < a.size(); i++) {
if (a[i] < i || vst[i] || !vst[a[i]]) continue;
ll val = simulateRange(a, i);
if (val > mx) {
mx = val;
mxA = i;
}
}
if (m == 0) continue;
if (mxA != -1) {
vector<ll> nw;
for (int j = 0; j < a.size(); j++) {
if (j == mxA) {
nw.push_back(mxA+2);
nw.push_back(a[mxA]+2);
nw.push_back(mxA);
continue;
}
if (a[j] == mxA) nw.push_back(mxA+1);
else nw.push_back(a[j] > mxA ? a[j]+2 : a[j]);
}
a = nw;
}
else {
a.push_back(a.size()+1);
a.push_back(a.size()-1);
}
}
cout << mx;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |