답안 #742121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742121 2023-05-15T16:09:35 Z CSQ31 Type Printer (IOI08_printer) C++17
20 / 100
92 ms 18336 KB
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
vii ch(26);
int ncnt = 0;
void add(int v,int i,string s){
	if(i==sz(s))return;
	int c = s[i] - 'a';
	if(!ch[c][v]){
		ch[c][v] = ++ncnt;
		for(int j=0;j<26;j++)ch[j].pb(0);
	}
	add(ch[c][v],i+1,s);
}
string ans,lng;
int idx = 0;
void print(int v,bool deep){
	int cnt = 0;
	for(int i=0;i<26;i++){
		if(ch[i][v])cnt++;
	}
	if(!cnt){
		ans+='P';
		return;
	}
	int c = deep?lng[idx]-'a' : -1;
	for(int i=0;i<26;i++){
		if(ch[i][v] && i != c){
			ans+=char('a'+i);
			print(ch[i][v],0);
			ans+='-';
		}
	}
	if(deep){
		ans+=char('a'+c);
		idx++;
		print(ch[c][v],1);
	}
	
}
int main()
{
	owo
	int n;
	cin>>n;
	for(int i=0;i<26;i++)ch[i].pb(0);
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(sz(s) > sz(lng))lng = s;
		add(0,0,s);
	}
	print(0,1);
	cout<<sz(ans)<<'\n';
	for(auto x:ans)cout<<x<<'\n';
	
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB didn't print every word
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1236 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 3540 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 7608 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 92 ms 18336 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 64 ms 14684 KB didn't print every word
2 Halted 0 ms 0 KB -