이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> n >> m;
vector<array<int,2>> v(2*n);
vector<int> p(2*n,-1);
for(int i=0;i<n;i++)
{
int l,r;
cin >> l >> r;
v[2*i]={l,2*i};
v[2*i+1]={r,2*i+1};
}
sort(v.begin(),v.end());
for(int i=0;i+1<2*n;i++) p[v[i][1]^1]=v[i+1][1];
vector<bool> vis(2*n,0);
vector<int> opt;
int res=0;
for(int i=0;i<2*n;i++)
{
int a=v[i][1];
if(vis[a]) continue;
int len=0;
while(a!=-1&&!vis[a])
{
len++;
vis[a]=1;
a=p[a];
}
if(a!=-1) opt.push_back(len);
else res+=len;
}
sort(opt.begin(),opt.end(),greater<>());
for(int len:opt)
{
if(m>0)
{
res+=(len+2);
m--;
}
}
res+=(4*(m/2));
if(m&1) res++;
cout << res << "\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... |