# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
522460 | Jesus | Type Printer (IOI08_printer) | C++17 | 53 ms | 49348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<char> ans;
struct arbol{
char letra;
int palabra_mayor;
bool fin_palabra=false;
vector<int> hijos;
};
int aux,desocupado=1;
arbol raices[500002];
int dfs(int posicion){
int tam=0;
for(int i:raices[posicion].hijos){
tam=max(dfs(i),tam);
}
tam++;
raices[posicion].palabra_mayor=tam;
return tam;
}
int res(int pos, bool rama){
if(pos!=0) {
ans.push_back(raices[pos].letra);
}
if(raices[pos].fin_palabra==true) {
ans.push_back('P');
}
int m=-1;
for(int i:raices[pos].hijos){
if(raices[i].palabra_mayor==raices[pos].palabra_mayor-1&&m==-1) m=i;
else res(i,false);
}
if(pos==0&&m!=-1) res(m,true);
else if(m!=-1) res(m,rama);
if(pos!=0&&rama==false) {
ans.push_back('-');
}
}
int main()
{
int n;
cin>>n;
string palabra;
bool c=false;
for(int i=0;i<n;i++){
cin>>palabra;
aux=0;
for(char l:palabra){
c=false;
for(int j:raices[aux].hijos){
if(raices[j].letra==l) {
c=true;
aux=j;
break;
}
}
if(c==false){
raices[aux].hijos.push_back(desocupado);
aux=desocupado;
raices[aux].letra=l;
desocupado++;
}
}
raices[aux].fin_palabra=true;
}
dfs(0);
res(0,false);
cout<<ans.size()<<endl;
for(char r:ans){
cout<<r<<endl;
}
return 0;
}
컴파일 시 표준 에러 (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... |