Submission #741157

# Submission time Handle Problem Language Result Execution time Memory
741157 2023-05-13T17:03:52 Z rainboy Travelling Salesperson (CCO20_day2problem1) C
25 / 25
441 ms 24280 KB
#include <stdio.h>
#include <string.h>

#define N	2000

int main() {
	static char cc[N][N + 1];
	static int prev[N], next[N];
	int n, i, j, k, p, q;

	scanf("%d", &n);
	for (i = 1; i < n; i++)
		scanf("%s", cc[i]);
	for (i = 0; i < n; i++)
		for (j = i + 1; j < n; j++)
			cc[i][j] = cc[j][i];
	for (i = 0; i < n; i++) {
		memset(prev, -1, n * sizeof *prev), memset(next, -1, n * sizeof *next);
		prev[i] = next[i] = i;
		for (k = 0, j = i; k < n; k++) {
			if (k == i)
				continue;
			if (j == i)
				next[i] = prev[i] = k, next[k] = prev[k] = i, j = k;
			else {
				p = prev[j], q = next[j];
				if (cc[j][k] == cc[p][j]) {
					next[j] = k, prev[k] = j, next[k] = q, prev[q] = k;
					if (q == i || cc[k][q] != cc[j][k])
						j = k;
					else
						j = q;
				} else {
					prev[j] = k, next[k] = j, prev[k] = p, next[p] = k;
					if (cc[k][p] != cc[j][k])
						j = k;
					else
						j = p == i ? prev[p] : p;
				}
			}
		}
		printf("%d\n", n);
		j = i;
		do {
			printf("%d ", j + 1);
		} while ((j = next[j]) != i);
		printf("\n");
	}
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:13:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%s", cc[i]);
      |   ^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 292 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 363 ms 24004 KB Output is correct
17 Correct 358 ms 23928 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 358 ms 23884 KB Output is correct
20 Correct 394 ms 24032 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 368 ms 23868 KB Output is correct
23 Correct 386 ms 23736 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 363 ms 23856 KB Output is correct
26 Correct 382 ms 23936 KB Output is correct
27 Correct 23 ms 2244 KB Output is correct
28 Correct 364 ms 23920 KB Output is correct
29 Correct 371 ms 23888 KB Output is correct
30 Correct 377 ms 24048 KB Output is correct
31 Correct 387 ms 24124 KB Output is correct
32 Correct 370 ms 23796 KB Output is correct
33 Correct 394 ms 24096 KB Output is correct
34 Correct 362 ms 23884 KB Output is correct
35 Correct 364 ms 24036 KB Output is correct
36 Correct 387 ms 24128 KB Output is correct
37 Correct 362 ms 23824 KB Output is correct
38 Correct 365 ms 23852 KB Output is correct
39 Correct 360 ms 23820 KB Output is correct
40 Correct 375 ms 24012 KB Output is correct
41 Correct 362 ms 23856 KB Output is correct
42 Correct 365 ms 23764 KB Output is correct
43 Correct 363 ms 23916 KB Output is correct
44 Correct 360 ms 23860 KB Output is correct
45 Correct 359 ms 24000 KB Output is correct
46 Correct 355 ms 23884 KB Output is correct
47 Correct 377 ms 23980 KB Output is correct
48 Correct 370 ms 23796 KB Output is correct
49 Correct 369 ms 24012 KB Output is correct
50 Correct 365 ms 23884 KB Output is correct
51 Correct 379 ms 23748 KB Output is correct
52 Correct 402 ms 24028 KB Output is correct
53 Correct 365 ms 23932 KB Output is correct
54 Correct 367 ms 24016 KB Output is correct
55 Correct 391 ms 24232 KB Output is correct
56 Correct 392 ms 23960 KB Output is correct
57 Correct 408 ms 24120 KB Output is correct
58 Correct 403 ms 23952 KB Output is correct
59 Correct 398 ms 24000 KB Output is correct
60 Correct 441 ms 24124 KB Output is correct
61 Correct 397 ms 24040 KB Output is correct
62 Correct 389 ms 23944 KB Output is correct
63 Correct 395 ms 24116 KB Output is correct
64 Correct 383 ms 24028 KB Output is correct
65 Correct 396 ms 24016 KB Output is correct
66 Correct 381 ms 23924 KB Output is correct
67 Correct 399 ms 24140 KB Output is correct
68 Correct 414 ms 24032 KB Output is correct
69 Correct 416 ms 24096 KB Output is correct
70 Correct 391 ms 23996 KB Output is correct
71 Correct 385 ms 23928 KB Output is correct
72 Correct 415 ms 24072 KB Output is correct
73 Correct 398 ms 24280 KB Output is correct
74 Correct 384 ms 24008 KB Output is correct
75 Correct 401 ms 24000 KB Output is correct
76 Correct 421 ms 23960 KB Output is correct
77 Correct 405 ms 23948 KB Output is correct
78 Correct 423 ms 24052 KB Output is correct
79 Correct 384 ms 24016 KB Output is correct
80 Correct 441 ms 24024 KB Output is correct
81 Correct 392 ms 24068 KB Output is correct
82 Correct 376 ms 23952 KB Output is correct
83 Correct 380 ms 24020 KB Output is correct
84 Correct 393 ms 23984 KB Output is correct
85 Correct 372 ms 24020 KB Output is correct
86 Correct 397 ms 23984 KB Output is correct
87 Correct 24 ms 2252 KB Output is correct
88 Correct 24 ms 2304 KB Output is correct
89 Correct 380 ms 24000 KB Output is correct
90 Correct 389 ms 24004 KB Output is correct
91 Correct 24 ms 2252 KB Output is correct
92 Correct 25 ms 2332 KB Output is correct
93 Correct 389 ms 24024 KB Output is correct
94 Correct 409 ms 23976 KB Output is correct
95 Correct 24 ms 2240 KB Output is correct
96 Correct 23 ms 2260 KB Output is correct
97 Correct 384 ms 23948 KB Output is correct
98 Correct 385 ms 24052 KB Output is correct