Submission #217748

#TimeUsernameProblemLanguageResultExecution timeMemory
217748mhy908Type Printer (IOI08_printer)C++14
100 / 100
198 ms126584 KiB
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define sortvec(x) sort(all(x)) #define compress(x) x.erase(unique(all(x)), x.end()) using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef pair<int, LL> pil; typedef pair<LL, int> pli; const LL llinf=1987654321987654321; const int inf=2000000000; int n, re; char input[30], ans[1000010]; struct TRIE{ struct NODE{ int pr, maxd; vector<int> vc; NODE* link[26]; NODE(){ pr=maxd=0; for(int i=0; i<26; i++)link[i]=0; } }*rt; TRIE(){rt=new NODE();} void update(NODE *nd, char str[], int lv){ if(!str[lv]){ nd->pr++; return; } nd->vc.pb(str[lv]-'a'); if(nd->link[str[lv]-'a']==0)nd->link[str[lv]-'a']=new NODE(); update(nd->link[str[lv]-'a'], str, lv+1); nd->maxd=max(nd->maxd, nd->link[str[lv]-'a']->maxd+1); } void update(char str[], int lv){update(rt, str, lv);} void print(NODE *nd){ sortvec(nd->vc); compress(nd->vc); vector<pii> tmp; for(auto i:nd->vc)tmp.pb(mp(nd->link[i]->maxd, i)); sortvec(tmp); for(int i=1; i<=nd->pr; i++)ans[++re]='P'; for(auto i:tmp){ ans[++re]='a'+i.S; print(nd->link[i.S]); } ans[++re]='-'; } void print(){print(rt);} }tr; int main(){ scanf("%d", &n); for(int i=1; i<=n; i++){ memset(input, 0, sizeof input); scanf("%s", input+1); tr.update(input, 1); } tr.print(); while(re){ if(ans[re]!='-')break; ans[re--]=0; } printf("%d\n", re); for(int i=1; i<=re; i++)printf("%c\n", ans[i]); }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
printer.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", input+1);
         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...