Submission #917336

#TimeUsernameProblemLanguageResultExecution timeMemory
917336rainboy줄서기 (KOI17_line)C++98
100 / 100
154 ms21836 KiB
#include <stdio.h> #include <stdlib.h> #define N 100000 int *ei[N], eo[N]; void append(int j, int i) { int o = eo[j]++; if (o >= 2 && (o & o - 1) == 0) ei[j] = (int *) realloc(ei[j], o * 2 * sizeof *ei[j]); ei[j][o] = i; } int main() { static int aa[N]; int n, m, h, i, j, o; scanf("%d%d", &n, &m); for (j = 0; j < n; j++) ei[j] = (int *) malloc(2 * sizeof *ei[j]); for (h = 0; h < m; h++) { scanf("%d%d", &i, &j), i--, j--; append(j, i); } for (j = 0; j < n; j++) { for (o = eo[j]; o--; ) { i = ei[j][o]; if (aa[i]++ < j - eo[j]) { printf("-1\n"); return 0; } } aa[j] = j - eo[j]; } for (i = 0; i < n; i++) printf("%d ", aa[i] + 1); printf("\n"); return 0; }

Compilation message (stderr)

line.cpp: In function 'void append(int, int)':
line.cpp:11:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   11 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
line.cpp: In function 'int main()':
line.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
line.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   scanf("%d%d", &i, &j), i--, j--;
      |   ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...