제출 #588290

#제출 시각아이디문제언어결과실행 시간메모리
588290Bench0310Teleporters (IOI08_teleporters)C++17
100 / 100
520 ms42972 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...