# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
477886 | 2021-10-04T11:34:46 Z | starplat | Type Printer (IOI08_printer) | C++14 | 175 ms | 61228 KB |
#include <bits/stdc++.h> using namespace std; vector<char> order,ans; int n,mxlen,ct,vis[550005]; vector<string > tmp; string s,mxs; struct node{ int word,ac[30],go; }trie[550005]; void add(string x,bool ok) { int curr=0; for (int i=0;i<x.length();i++){ if (!trie[curr].ac[x[i]-'a']) trie[curr].ac[x[i]-'a']=++ct; curr=trie[curr].ac[x[i]-'a']; trie[curr].go=ok; //if (trie[curr].go==true) cout<<curr<<"\n"; } trie[curr].word=1; } void dfs(int curr) { vis[curr]=1; if (trie[curr].word) ans.push_back('P'); int dumb=-1; for (int i=0;i<26;i++){ int node=trie[curr].ac[i]; if (node==0) continue; if (vis[node]) continue; //if (curr==27) cout<<node<<" "<<trie[node].go<<"\n"; if (trie[node].go==1) { dumb=i; // cout<<trie[node].go<<" "<<curr<<" "<<dumb<<"\n" ; } else { ans.push_back(char(i+'a')); dfs(node); ans.push_back('-'); } } //cout<<dumb<<"\n"; if (dumb>-1){ //cout<<trie[curr].ac[dumb]<<"\n"; ans.push_back(char(dumb+'a')); dfs(trie[curr].ac[dumb]); } } int main() { cin>>n; for (int i=0;i<n;i++){ cin>>s; if (s.length()>mxlen) mxlen=s.length(),mxs=s,tmp.clear(); else if (s.length()==mxlen){ tmp.push_back(s); } add(s,0); } tmp.push_back(mxs); sort(tmp.begin(),tmp.end()); mxs=tmp[tmp.size()-1]; add(mxs,1); dfs(0); //dfs(trie[0].ac[mxs[0]-'a']); cout<<ans.size()<<"\n"; for (char c:ans) cout<<c<<"\n"; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 2 ms | 716 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1228 KB | Output is correct |
2 | Correct | 3 ms | 1484 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 3660 KB | Output is correct |
2 | Correct | 19 ms | 7604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 9032 KB | Output is correct |
2 | Correct | 12 ms | 2380 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 22048 KB | Output is correct |
2 | Correct | 126 ms | 51540 KB | Output is correct |
3 | Correct | 76 ms | 26384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 50 ms | 17244 KB | Output is correct |
2 | Correct | 175 ms | 61228 KB | Output is correct |
3 | Correct | 81 ms | 29404 KB | Output is correct |
4 | Correct | 134 ms | 58172 KB | Output is correct |