Submission #604723

#TimeUsernameProblemLanguageResultExecution timeMemory
604723nekiType Printer (IOI08_printer)C++14
100 / 100
170 ms57940 KiB
#include <bits/stdc++.h> #define ll long long #define vc vector using namespace std; const ll mn =500100; ll cnt=0; map<char, ll> tr[mn]; ll konci[mn]; void add(string s){ ll cur=0; for(auto v: s){ if(tr[cur].find(v)==tr[cur].end()) tr[cur][v]=++cnt; cur=tr[cur][v]; } assert(cnt<mn); assert(cur<mn); ++konci[cur]; } vc<char> ans; void dfs(ll u, string& izogni, ll ind){ for(ll i=0;i<konci[u];++i) ans.push_back('P'); for(auto v: tr[u]){ if(ind<izogni.size() and v.first==izogni[ind]) continue; ans.push_back(v.first); dfs(v.second, izogni, ind+1); ans.push_back('-'); } if(ind<izogni.size() and tr[u].find(izogni[ind])!=tr[u].end()){ ans.push_back(izogni[ind]); dfs(tr[u][izogni[ind]], izogni, ind+1); ans.push_back('-'); } } int main() { ll n;cin >> n; string l=""; for(ll i=0;i<n;++i){ string s;cin >> s; if(l.size()<s.size()) l=s; add(s); } dfs(0, l, 0); while(ans.back()=='-') ans.pop_back(); cout << ans.size()<<'\n'; for(auto v: ans) cout << v << '\n'; }

Compilation message (stderr)

printer.cpp: In function 'void dfs(long long int, std::string&, long long int)':
printer.cpp:27:15: 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]
   27 |         if(ind<izogni.size() and v.first==izogni[ind]) continue;
      |            ~~~^~~~~~~~~~~~~~
printer.cpp:33:11: 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]
   33 |     if(ind<izogni.size() and tr[u].find(izogni[ind])!=tr[u].end()){
      |        ~~~^~~~~~~~~~~~~~
#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...