# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
115182 | 2019-06-05T23:06:28 Z | ly20 | Type Printer (IOI08_printer) | C++14 | 63 ms | 22740 KB |
#include<bits/stdc++.h> using namespace std; #define debug(args...) //fprintf(stderr,args) #define end end1 const int MAXN=25010,MAXL=30; int trie[MAXN*MAXL][MAXL],vl[MAXN*MAXL],cont[MAXN*MAXL],pos[MAXN*MAXL],end[MAXN*MAXL],pt[MAXN*MAXL]; int at; vector<char> rs; string s1; string sr; int tmn; void tr(int v) { debug("%c %d %d\n",vl[v]+'a',pt[v],v); if(v!=0) { rs.push_back(vl[v]+'a'); } for(int i=0;i<MAXL;i++) { if(trie[v][i]!=0 && pt[trie[v][i]]!=1) { tr(trie[v][i]); if(end[trie[v][i]])rs.push_back('P'); rs.push_back('-'); } } int id; debug("tam=%d pos=%d\n",tmn,pos[v]); if(tmn>pos[v]) { id=sr[pos[v]]-'a'; debug("%c %d %d\n",sr[pos[v]],pt[trie[v][id]]); if(pt[trie[v][id]]==1) { debug("oi\n"); tr(trie[v][id]); if(end[trie[v][id]])rs.push_back('P'); } } } void add(string s) { int cur=0; int tm=s.size(); for(int i=0;i<tm;i++) { cont[cur]++; int id=s[i]-'a'; if(trie[cur][id]==0) { trie[cur][id]=++at; vl[at]=id; pos[at]=i+1; } cur=trie[cur][id]; } end[cur]=1; } void pt1(string s) { int cur=0; int tm=s.size(); for(int i=0;i<tm;i++) { int id=s[i]-'a'; cur=trie[cur][id]; pt[cur]=1; } } int main() { int n; scanf("%d",&n); for(int i=0;i<n;i++) { cin>>s1; if(s1.size()>sr.size())sr=s1; add(s1); } pt1(sr); tmn=sr.size(); tr(0); for(int i=0;i<tmn;i++)debug("%c",sr[i]); debug("\n"); for(int i=0;i<30;i++)debug("%d\n",pos[i]); printf("%d\n",rs.size()); for(int i=0;i<rs.size();i++)printf("%c\n",rs[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 384 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Incorrect | 2 ms | 384 KB | printed invalid word |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 512 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 1280 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 11 ms | 3968 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 26 ms | 9332 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 63 ms | 22740 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 55 ms | 18032 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |