답안 #53695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53695 2018-07-01T04:53:36 Z 강한남자강한필(#2035) Type Printer (IOI08_printer) C++11
0 / 100
61 ms 18816 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 25000;
const int MAXC = 20;
struct Node
{
	bool dest;
	int next[26];
	int lastvisit;
};

int used = 1;
Node arr[MAXN*MAXC+1];

int tp = 0;
char ans[2*MAXN*(MAXC+2)];

int root = 1;
int maxlength = 0;
void traverse(int node)
{
	//printf("%d %d %d\n", node, arr[node].dest, arr[node].lastvisit);
	if(arr[node].dest) ans[tp++] = 'P';
	for(int i=0; i<arr[node].lastvisit; ++i)
		if(arr[node].next[i])
		{
			ans[tp++] = 'a' + i;
			traverse(arr[node].next[i]);
		}
	for(int i=arr[node].lastvisit+1; i<26; ++i)
		if(arr[node].next[i])
		{
			ans[tp++] = 'a' + i;
			traverse(arr[node].next[i]);
		}
	if(arr[node].lastvisit)
	{
		ans[tp++] = 'a'+arr[node].lastvisit;
		traverse(arr[node].next[arr[node].lastvisit]);
	}
	ans[tp++] = '-';
}

bool push(int node, char* buf, int depth)
{
	if(*buf == 0)
	{
		arr[node].dest = true;
		if(maxlength < depth)
		{
			maxlength = depth;
			return true;
		}
		return false;
	}
	else
	{
		int targ = (*buf) - 'a';
		//printf("%d\n", targ);
		if(arr[node].next[targ] == 0)
			arr[node].next[targ] = ++used;
		bool res = push(arr[node].next[targ], buf+1, depth+1);
		if(res) arr[node].lastvisit = targ;
	}
}

int main()
{
	int N;
	scanf("%d", &N);
	for(int i=0; i<N; ++i)
	{
		char buf[MAXC+1];
		scanf("%s", buf);
		push(root, buf, 0);
	}
	traverse(root);
	printf("%d\n",tp-maxlength-1);
	for(int i=0; i<tp-maxlength-1; ++i)
		printf("%c\n", ans[i]);
	return 0;
}

Compilation message

printer.cpp: In function 'bool push(int, char*, int)':
printer.cpp:66:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
printer.cpp: In function 'int main()':
printer.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
printer.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", buf);
   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 3 ms 360 KB didn't print every word
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 408 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 468 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 468 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 472 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1236 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 3384 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 7828 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 18816 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 61 ms 18816 KB didn't print every word
2 Halted 0 ms 0 KB -