답안 #115181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115181 2019-06-05T23:02:36 Z CaroLinda Type Printer (IOI08_printer) C++14
10 / 100
468 ms 21532 KB
#include <bits/stdc++.h>

#define pii pair<int,int>
#define lp(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define ff first
#define ss second
#define pb push_back

const int MAXN = 25005;
const int ALF= 30;

using namespace std ;

int n ;
int trie[MAXN*20][ALF] , cnt ;
vector<char> ans ;

void add( string str )
{
	
	int t = str.size() ;
	
	int cur = 0 ;
	
	lp(i,0,t)
	{
		
		int k = str[i] - 'a' ;
		
		if(trie[cur][k] == 0) trie[cur][k] = ++cnt ;
		
		cur = trie[cur][k] ;
		
	}
	
}

bool comp(string s1, string s2)
{ return s1.size() < s2.size() ; }

void dfs(int x)
{
	vector<pii> v ;
	
	lp(i,0,27)
	if( trie[x][i]!= 0 ) v.pb(pii( trie[x][i] , i+'a' )) ;
	
	sort(v.begin() , v.end()) ;
	
	lp(i,0,v.size())
	{
		char c = v[i].ss;
		ans.pb(c) ;
		dfs(v[i].ff) ;
		ans.pb('-') ;
	}
	
	if( v.size() == 0 ) ans.pb('P') ;
	
}

int main()
{
	
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	
	cin>>n ;
	
	vector<string> v ;
	
	string s ;
	
	lp(i,0,n) { cin>>s ; v.pb(s) ;  }
	
	sort(v.begin() , v.end(), comp ) ;
	
	lp(i,0,n) add(v[i]) ;

	dfs(0) ;
	
	cout<<ans.size() - v[n-1].size() <<endl ;
	
	lp(i,0,ans.size() - v[n-1].size()) cout<<ans[i]<<endl ;
	
}

Compilation message

printer.cpp: In function 'void dfs(int)':
printer.cpp:4:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define lp(i,a,b) for(int i=a;i<b;i++)
printer.cpp:51:5:
  lp(i,0,v.size())
     ~~~~~~~~~~~~                
printer.cpp:51:2: note: in expansion of macro 'lp'
  lp(i,0,v.size())
  ^~
printer.cpp: In function 'int main()':
printer.cpp:4:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define lp(i,a,b) for(int i=a;i<b;i++)
printer.cpp:85:5:
  lp(i,0,ans.size() - v[n-1].size()) cout<<ans[i]<<endl ;
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:85:2: note: in expansion of macro 'lp'
  lp(i,0,ans.size() - v[n-1].size()) cout<<ans[i]<<endl ;
  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB didn't print every word
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 1264 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 3840 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 186 ms 8832 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 468 ms 21532 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 384 ms 17264 KB didn't print every word
2 Halted 0 ms 0 KB -