Submission #717174

#TimeUsernameProblemLanguageResultExecution timeMemory
717174aedmhsnType Printer (IOI08_printer)C++17
100 / 100
168 ms68160 KiB
#include <bits/stdc++.h> using namespace std; #define A first #define B second #define MP make_pair #define ms(a, x) memset(a, x, sizeof(a)) #define boost() ios_base::sync_with_stdio(false); cin.tie(0) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<long double, long double> pld; const int INF = 0x3f3f3f3f; const ll LLINF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1); struct Vertex{ vector <int> nxt; bool leaf=false; int longest=0; Vertex(){ nxt.resize(26, -1); } }; vector <Vertex> trie(1); void add_string(string &s){ int v=0; for(int i=0; i<s.size(); i++){ int c = s[i]-'a'; if(trie[v].nxt[c] == -1){ trie[v].nxt[c] = trie.size(); trie.emplace_back(); } trie[v].longest = max(trie[v].longest, (int)s.size()-i-1); v=trie[v].nxt[c]; } trie[v].leaf=true; } vector <char> ans; // so i think there is a couple of ideas // we can maybe sort them by size then do the print function such that it marks the strings visited ? // well this is wierd // void solve(int v){ if(trie[v].leaf) ans.push_back('P'); vector <pii> nodes; for(int i=0; i<26; i++){ if(trie[v].nxt[i] != -1){ nodes.push_back({trie[trie[v].nxt[i]].longest, i}); } } sort(nodes.begin(), nodes.end()); for(auto x:nodes){ ans.push_back(x.B+'a'); solve(trie[v].nxt[x.B]); ans.push_back('-'); } } int main(){ int n; cin >> n; vector <string> a(n); for(int i=0; i<n; i++){ cin >> a[i]; add_string(a[i]); } solve(0); while(ans.back() == '-'){ ans.pop_back(); } cout << ans.size() << '\n'; for(auto x:ans) cout << x << '\n'; }

Compilation message (stderr)

printer.cpp: In function 'void add_string(std::string&)':
printer.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=0; i<s.size(); i++){
      |                  ~^~~~~~~~~
#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...