Submission #53693

# Submission time Handle Problem Language Result Execution time Memory
53693 2018-07-01T04:52:29 Z 강한육군장홍준(#2037) Type Printer (IOI08_printer) C++11
20 / 100
76 ms 19040 KB
#include<stdio.h>
#include<string.h>
struct ND {
	int nxt[26], lp;
	bool is_ed;
}a[500001];
char ans[1212121], S[21];int an, sz;
int max(int a, int b) { if (a < b)return b; return a; }
void mk() {
	int now = 0, L = strlen(S);
	for (int i = 0; i < L; i++) {
		if (!a[now].nxt[S[i] - 'a'])a[now].nxt[S[i] - 'a'] = ++sz;
		now = a[now].nxt[S[i] - 'a'];
		a[now].lp = max(a[now].lp, L);
	}
	a[now].is_ed = 1;
}
void dfs(int now) {
	int mx = 0, mxw = -1;
	for (int i = 0; i < 26; i++)if (mx < a[a[now].nxt[i]].lp)mx = a[a[now].nxt[i]].lp, mxw = i;
	for (int i = 0; i < 26; i++)if (a[now].nxt[i]) {
		if (i == mxw)continue;
		ans[an++] = 'a' + i;
		dfs(a[now].nxt[i]);
	}
	if (mxw != -1) {
		ans[an++] = 'a' + mxw;
		dfs(a[now].nxt[mxw]);
	}
	if (a[now].is_ed)ans[an++] = 'P';
	ans[an++] = '-';
}
int main() {
	int n, i; scanf("%d", &n);
	for (i = 0; i < n; i++)scanf("%s", S), mk();
	dfs(0);
	while (ans[an - 1] == '-')an--;
	printf("%d\n", an);
	for (i = 0; i < an; i++)printf("%c\n", ans[i]);
	return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:34:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n, i; scanf("%d", &n);
            ~~~~~^~~~~~~~~~
printer.cpp:35:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 0; i < n; i++)scanf("%s", S), mk();
                         ~~~~~~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 436 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 548 KB Output is correct
2 Incorrect 2 ms 548 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 3392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 7888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 76 ms 19040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 19040 KB Output isn't correct
2 Halted 0 ms 0 KB -