답안 #198778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198778 2020-01-27T15:28:25 Z arnold518 Type Printer (IOI08_printer) C++14
20 / 100
132 ms 41716 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 25000;

int N;
string S;
vector<char> ans;

struct Node
{
	int dep;
	Node *chd[30];
	Node()
	{
		int i, j;
		for(i=0; i<26; i++) chd[i]=NULL;
	}

	void update(string &S)
	{
		if(S.empty()) return;
		char c=S.back(); S.pop_back();
		if(chd[c-'a']==NULL) chd[c-'a']=new Node();
		chd[c-'a']->update(S);
	}

	void calc()
	{
		int i, j;
		for(i=0; i<26; i++)
		{
			if(chd[i]==NULL) continue;
			chd[i]->calc();
			dep=max(dep, chd[i]->dep+1);
		}
	}

	void dfs()
	{
		int i, j;
		int cnt=0;
		vector<int> V;
		for(i=0; i<26; i++)
		{
			if(chd[i]==NULL) continue;
			V.push_back(i);
		}
 
		sort(V.begin(), V.end(), [&](const int &p, const int &q) { return chd[p]->dep<chd[q]->dep; });
		for(auto i : V)
		{
			cnt++; ans.push_back(i+'a');
			chd[i]->dfs();
			ans.push_back('-');
		}
		if(cnt==0) ans.push_back('P');
	}
};

Node *root=new Node();

int main()
{
	int i, j;

	cin>>N;
	for(i=1; i<=N; i++)
	{
		cin>>S;
		reverse(S.begin(), S.end());
		root->update(S);
	}
	root->calc();
	root->dfs();
	while(!ans.empty() && ans.back()=='-') ans.pop_back();
	printf("%d\n", ans.size());
	for(auto it : ans) printf("%c\n", it);
}

Compilation message

printer.cpp: In constructor 'Node::Node()':
printer.cpp:20:10: warning: unused variable 'j' [-Wunused-variable]
   int i, j;
          ^
printer.cpp: In member function 'void Node::calc()':
printer.cpp:34:10: warning: unused variable 'j' [-Wunused-variable]
   int i, j;
          ^
printer.cpp: In member function 'void Node::dfs()':
printer.cpp:45:10: warning: unused variable 'j' [-Wunused-variable]
   int i, j;
          ^
printer.cpp: In function 'int main()':
printer.cpp:81:27: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", ans.size());
                 ~~~~~~~~~~^
printer.cpp:69:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 6 ms 376 KB didn't print every word
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 504 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 2040 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 6776 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 16760 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 132 ms 41716 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 107 ms 32624 KB didn't print every word
2 Halted 0 ms 0 KB -