이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define N 1000005
#define II pair <int,int>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x))
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
using namespace std;
int n,m,End[2*N],From[2*N],i,u,sz,l,r,res,nxt[2*N],node,last;
bool visited[N];
II a[2*N];
int rev(int u) { return (u<=n) ? u+n : u-n; }
int main()
{
// freopen("teleporters.inp","r",stdin);
//freopen("teleporters.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>m;
a[++sz]={ 0,0 }; a[++sz]={ 2000001,2*n+1 };
for(i=1;i<=n;i++)
{
cin>>l>>r;
a[++sz]={ l,i }; a[++sz]={ r,rev(i) };
}
sort(a+1,a+sz+1);
for(i=2;i<=sz;i++) End[++node]=a[i].snd,From[a[i-1].snd]=node;
for(u=1;u<=node;u++) nxt[u]=From[rev(End[u])];
for(u=1;u<node;u=nxt[u]) visited[u]=1,res++;
visited[node]=1;
priority_queue <int> h;
for(u=2;u<=node;u++)
if(visited[u]==0)
{
int v=nxt[u],edge=0;
while(v!=u) visited[v]=1,edge++,v=nxt[v];
visited[v]=1,edge++;
h.push(edge);
}
for(i=1;i<=m;i++)
if(h.size()>0)
{
int k=h.top(); h.pop();
res+=k+2;
}
else
{
res++;
h.push(1);
}
cout<<res;
}
# | 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... |