Submission #811003

#TimeUsernameProblemLanguageResultExecution timeMemory
811003sofija6Type Printer (IOI08_printer)C++14
100 / 100
93 ms41020 KiB
#include <bits/stdc++.h> #define ll long long #define MAXC 1000010 using namespace std; vector<ll> G[MAXC]; vector<char> ans; char val[MAXC]; string s,maxx; ll ind=2; bool lastt[MAXC],endd[MAXC]; void Add(ll cur,ll pos) { if (pos==s.size()) { endd[cur]=true; return; } ll x=-1; for (ll next : G[cur]) { if (val[next]==s[pos]) x=next; } if (x==-1) { x=ind++; val[x]=s[pos]; G[cur].push_back(x); } Add(x,pos+1); } void Find(ll cur,ll pos) { lastt[cur]=true; if (pos==maxx.size()) return; ll x=-1; for (ll next : G[cur]) { if (val[next]==maxx[pos]) x=next; } Find(x,pos+1); } void Solve(ll cur) { if (endd[cur]) ans.push_back('P'); for (ll next : G[cur]) { if (!lastt[next]) { ans.push_back(val[next]); Solve(next); } } for (ll next : G[cur]) { if (lastt[next]) { ans.push_back(val[next]); Solve(next); } } if (!lastt[cur]) ans.push_back('-'); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; for (ll i=1;i<=n;i++) { cin >> s; Add(1,0); if (s.size()>maxx.size()) maxx=s; } Find(1,0); Solve(1); cout << ans.size() << "\n"; for (char i : ans) cout << i << "\n"; return 0; }

Compilation message (stderr)

printer.cpp: In function 'void Add(long long int, long long int)':
printer.cpp:13:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     if (pos==s.size())
      |         ~~~^~~~~~~~~~
printer.cpp: In function 'void Find(long long int, long long int)':
printer.cpp:35:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     if (pos==maxx.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...