Submission #53692

# Submission time Handle Problem Language Result Execution time Memory
53692 2018-07-01T04:51:14 Z 강한육군장홍준(#2037) Type Printer (IOI08_printer) C++11
20 / 100
71 ms 19144 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;
		a[now].lp = max(a[now].lp, L);
		now = a[now].nxt[S[i] - 'a'];
	}
	a[now].is_ed = 1;
}
void dfs(int now) {
	int mx = 0, mxw = -1;
	for (int i = 0; i < 26; i++)if(a[now].nxt[i] && 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 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 432 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 532 KB Output is correct
2 Incorrect 2 ms 532 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 3452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 7904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 19144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 19144 KB Output isn't correct
2 Halted 0 ms 0 KB -