제출 #1029528

#제출 시각아이디문제언어결과실행 시간메모리
1029528sleepntsheepTeleporters (IOI08_teleporters)C11
100 / 100
232 ms65536 KiB
#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 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...