이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define rep(a) for(int i = 0; i < a; i++)
#define each(i,a) for(auto&& i : a)
#define all(a) begin(a), end(a)
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<pii> a(n);
vector<int> x;
each(i, a){
int a, b;
cin >> a >> b;
i = {a, b};
x.push_back(a);
x.push_back(b);
}
sort(all(x));
x.erase(unique(all(x)), x.end());
vector<int> to(n * 2);
each(i, a){
i.first = lower_bound(all(x), i.first) - x.begin();
i.second = lower_bound(all(x), i.second) - x.begin();
to[i.first] = i.second;
to[i.second] = i.first;
}
vector<int> color(n * 2, -1), cnt;
int at = 0, c = 0, ans = 0;
while(at != n * 2){
color[at] = c;
ans++;
at = to[at] + 1;
}
rep(n * 2) if(color[i] == -1){
cnt.push_back(0);
int at = i; c++;
while(at != n * 2 && color[at] == -1){
color[at] = c;
cnt.back()++;
at = to[at] + 1;
}
}
sort(all(cnt));
while(cnt.size() && m){
ans += cnt.back() + 2;
cnt.pop_back();
m--;
}
ans += m / 2 * 4 + m % 2;
cout << ans << endl;
}
# | 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... |