Submission #880667

#TimeUsernameProblemLanguageResultExecution timeMemory
880667OAleksaType Printer (IOI08_printer)C++14
10 / 100
43 ms41068 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define f first #define s second vector<char> ans; const int maxn = 5e5 + 69; int trie[maxn][26], kraj[maxn], ban[maxn]; int n, node; void add(string s) { int m = s.size(); int t = 0; for (int i = 0;i < m;i++) { int x = s[i] - 'a'; if (trie[t][x] == 0) trie[t][x] = ++node; t = trie[t][x]; } kraj[t]++; } void dfs(int v) { for (int i = 0;i < kraj[v];i++) ans.push_back('P'); int x = -1; for (int i = 0;i < 26;i++) { if (trie[v][i] && ban[trie[v][i]] != 1) { ans.push_back((char)(i + 'a')); dfs(trie[v][i]); ans.push_back('-'); } else if (ban[trie[v][i]] == 1) x = i; } if (x != -1) { ans.push_back((char)(x + 'a')); dfs(trie[v][x]); ans.push_back('-'); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n; vector<string> a(n); for (int i = 0;i < n;i++) { cin >> a[i]; add(a[i]); } sort(a.begin(), a.end()); int t = 0; for (int i = 0;i < a.back().size();i++) { int x = a[n - 1][i] - 'a'; t = trie[t][x]; ban[t] = 1; } dfs(0); while (ans.back() == '-') ans.pop_back(); cout << ans.size() << '\n'; for (auto x : ans) cout << x << '\n'; } return 0; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:55:22: 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]
   55 |     for (int i = 0;i < a.back().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...