Submission #53696

# Submission time Handle Problem Language Result Execution time Memory
53696 2018-07-01T04:54:38 Z 강한육군장홍준(#2037) Type Printer (IOI08_printer) C++11
20 / 100
96 ms 19016 KB
#include<stdio.h>
#include<string.h>
struct ND {
	int nxt[26], lp;
	int is_ed;
}a[500001];
char ans[1212121], S[221];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++;
}
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]);
	}
	for(int i=0;i<a[now].is_ed;i++)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 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 392 KB Output is correct
2 Correct 2 ms 392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 440 KB Output is correct
2 Incorrect 2 ms 620 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 3384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 7880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 19016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 19016 KB Output isn't correct
2 Halted 0 ms 0 KB -