이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MxP = 2000020;
int nxt[MxP];
bool visited[MxP];
signed main(int argc, char *argv[]) {
cin.tie(nullptr)->ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for(int i=0; i<MxP - 1; ++i) {
nxt[i] = i + 1;
}
nxt[MxP - 1] = 1;
for(int i=1, l, r; i<=n; ++i) {
cin >> l >> r;
nxt[l - 1] = r;
nxt[r - 1] = l;
}
vector<int> v;
for(int i=0; i<MxP; ++i) {
if(visited[i]) {
continue;
}
int cur = i, cnt_warp = 0;
while(!visited[cur]) {
visited[cur] = true;
if(nxt[cur] != cur + 1) {
cnt_warp++;
}
cur = nxt[cur];
}
v.emplace_back(cnt_warp);
}
int answer = v[0] + (m + 1) / 2 + (m / 2) * 3;
sort(v.begin(), v.end(), greater<int> ());
for(int i=0; i<m && i<(int) v.size(); ++i) {
answer += 2 + v[i];
}
cout << answer << "\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... |