Submission #855115

#TimeUsernameProblemLanguageResultExecution timeMemory
855115vjudge1Type Printer (IOI08_printer)C++17
90 / 100
74 ms49420 KiB
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; typedef long long LL; #define fi first #define se second #define _for(ccc, sss, eee) for (int ccc=(sss);ccc<=(eee);ccc++) #define __for(ccc, sss, eee) for (int ccc=(sss);ccc>=(eee);ccc--) #define N 25000 #define M 26 #define INF 0x7f7f7f7f struct node{ int son[M]; bool is_lest, is_end; // 是最长的 是一个单词 }pool[N*20];//一共25000个词语, 每个词语最长20 int sz=0;//大小 inline void ins(const string &x){ int cur=0; for (auto &c:x){ int &nex=pool[cur].son[c-'a']; if (!nex)nex=++sz; cur=nex; } pool[cur].is_end=true; } void DFS(int cur, string &ans){ const node &x=pool[cur]; if (x.is_end)ans+='P'; int ind=-1, nex; _for (i, 0, M-1){ nex=x.son[i];//下一个节点 if (!nex)continue;//没有 if (pool[nex].is_lest)ind=i; else ans+=i+'a', DFS(nex, ans); } if (ind!=-1)ans+=ind+'a', DFS(x.son[ind], ans); ans+='-'; } int main(){ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);//如果写freopen()删掉cout.tie() int n; string s, lest; cin>>n; _for (i, 0, n-1){ cin>>s, ins(s); if (s.size()>lest.size())lest=s; } int last=0; _for (i, 0, lest.size()){//标记最后走 last=pool[last].son[lest[i]-'a']; pool[last].is_lest=true; } s.clear(); DFS(0, s); while (*(s.end()-1)=='-')s.pop_back();//最后不用退出 cout<<s.size()<<'\n'; for (auto &c:s)cout<<c<<'\n'; return 0; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:10:51: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define _for(ccc, sss, eee) for (int ccc=(sss);ccc<=(eee);ccc++)
      |                                                   ^
printer.cpp:55:2: note: in expansion of macro '_for'
   55 |  _for (i, 0, lest.size()){//标记最后走
      |  ^~~~
#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...