# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
546177 | smth | Type Printer (IOI08_printer) | C++14 | 150 ms | 106316 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#define endl '\n'
using namespace std;
char res[1000000];
int len=0;
struct trie
{
trie* chil[27];
bool word;
int dep;
trie()
{
for(int i=0;i<27;i++)chil[i]=NULL;
word = 0;
dep = 0;
}
};
trie* root = new trie;
void add(trie* curr, string& word, int ind)
{
if(ind==word.size())
{
curr->word=true;
return;
}
int let=word[ind]-'a';
if(curr->chil[let]==NULL)curr->chil[let]=new trie;
add(curr->chil[let], word, ind+1);
curr->dep = max(curr->dep, curr->chil[let]->dep+1);
}
void sear(trie* curr, int ind)
{
if(curr==NULL)
{
return;
}
if(curr->word==true)res[len++]='P';
int maxi=0;
for(int i=0;i<27;i++){
if(curr->chil[i]!=NULL) {maxi=max(maxi,curr->chil[i]->dep); }
}
for(int i=0;i<27;i++){
if(curr->chil[i]!=NULL && curr->chil[i]->dep!=maxi) { res[len++]=char(i+'a');sear(curr->chil[i],ind+1);}
}
for(int i=0;i<27;i++){
if(curr->chil[i]!=NULL && curr->chil[i]->dep==maxi) { res[len++]=char(i+'a');sear(curr->chil[i],ind+1);}
}
res[len++]='-';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, q, i, j, t, k,x,ind=0;
string s1, s;
cin>>n;
while(n--)
{
cin>>s;
add(root,s,0);
}
sear(root, 0);
for(i=len-1;i>=0;i--)
{
if(res[i]!='-')break;
} ind =i;
cout<<ind+1<<endl;
for(i=0;i<=ind;i++)cout<<res[i]<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |