이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<pair<int, int> > v(2 * n + 2);
v[0] = { 0, 0 }, v[1] = { 2e6 + 5, 1 };
for (int i = 1; i <= n; i++)
{
cin >> v[2 * i].first >> v[2 * i + 1].first;
v[2 * i].second = 2 * i, v[2 * i + 1].second = 2 * i + 1;
}
sort(v.begin(), v.end());
int last = v.back().second;
int k = v.size();
vector<int> nx(k, -1);
for (int i = k - 1; i >= 0; i--)
{
nx[v[i].second] = (last < 2 ? last : last ^ 1);
last = v[i].second;
}
vector<bool> vis(k, false);
int path = -1; vector<int> c;
for (int i = 0; i < k; i++) if (!vis[i])
{
int j = i, len = 0;
while (!vis[j])
{
vis[j] = true;
len++, j = nx[j];
}
if (!i) path = len-2;
else c.push_back(len);
}
sort(c.begin(), c.end());
while (m && c.size())
{
path += c.back() + 2;
c.pop_back(); m--;
}
path += ((m >> 1) << 2) + (m & 1);
cout << path << "\n";
return 0;
}
# | 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... |