# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1046178 | Zicrus | Teleporters (IOI08_teleporters) | C++17 | 1064 ms | 65536 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |