이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 1000000
#define A 2000002
int pos[2*N], n, m, a[N], b[N], count[A], next[A], o;
int succ[A], sussy[A], cyclen, cyc[A], ii;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i)
scanf("%d%d", a+i, b+i),
++count[a[i]], ++count[b[i]];
for (int i = 0; i < sizeof succ / sizeof *succ; ++i)
succ[i] = -1;
for (int o = 0, i = 0; i < A; ++i)
while (count[i]) pos[o++] = i, --count[i];
for (int i = 1; i < 2 * n; ++i)
next[pos[i-1]] = pos[i];
next[pos[2*n-1]] = 2000001;
succ[0] = pos[0];
for (int i = 0; i < n; ++i)
succ[a[i]] = next[b[i]], succ[b[i]] = next[a[i]];
int len = -1, cur = 0;
while (cur != 2000001)
sussy[cur] = 1, ++len, cur = succ[cur];
sussy[2000001] = 1;
for (int i = 0; i <= 2000000; ++i) {
if (-1 < succ[i] && !sussy[i]) {
cyclen = 1;
cur = succ[i];
sussy[i] = -1;
while (cur != i)
++cyclen, sussy[cur] = -1, cur = succ[cur];
++count[cyclen];
}
}
for (int i = 2000000; i >= 1; --i)
while (count[i]) cyc[o++] = i, --count[i];
while (ii < o && m)
--m, len += cyc[ii++] + 2;
len += 4 * (m / 2);
if (m & 1) ++len;
printf("%d", len);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
teleporters.c: In function 'main':
teleporters.c:10:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
teleporters.c:12:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d%d", a+i, b+i),
| ^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |