Submission #689937

#TimeUsernameProblemLanguageResultExecution timeMemory
689937gagik_2007Type Printer (IOI08_printer)C++17
0 / 100
419 ms29332 KiB
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <chrono> #include <ctime> #include <set> #include <map> #include <stack> #include <queue> #include <deque> #include <limits> #include <iomanip> #include <unordered_set> #include <unordered_map> #include <fstream> #include <functional> #include <random> #include <cassert> using namespace std; typedef long long ll; typedef long double ld; #define ff first #define ss second const int K = 26; class Vertex { public: int size; bool word; int to[K]; Vertex() { fill(to, to + K, -1); size = 0; word = false; } }; ll ttt; const ll INF = 1e18; const ll MOD = 1e9 + 7; const ll N = 1000007; ll n, m, k; vector<Vertex>p(1); vector<char>ans; void add(const string& s) { int v = 0; for (auto ch : s) { int c = ch - 'a'; if (p[v].to[c] == -1) { p[v].to[c] = p.size(); p.emplace_back(); } v = p[v].to[c]; } p[v].word = true; } void calc_size(int v) { p[v].size = 1; for (int i = 0; i < K; i++) { if (p[v].to[i] != -1) { calc_size(p[v].to[i]); p[v].size += p[p[v].to[i]].size; } } } void dfs(int v) { if (p[v].word) { ans.push_back('P'); } vector<pair<int, int>>d; for (int i = 0; i < K; i++) { if (p[v].to[i] != -1) { d.push_back({ p[p[v].to[i]].size,p[v].to[i] }); } } sort(d.begin(), d.end()); for (int i = 0; i < d.size(); i++) { ans.push_back(d[i].ss + 'a'); dfs(d[i].ss); ans.push_back('-'); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; add(s); } calc_size(0); dfs(0); while ((*ans.rbegin()) == '-') { ans.pop_back(); } cout << ans.size() << endl; for (auto x : ans) { cout << x << endl; } return 0; } /// ---- - -------- ------ -------- -- - - - /// Just a reminder. Ubuntu password is I O I /// ---- - -------- ------ -------- -- - - -

Compilation message (stderr)

printer.cpp: In function 'void dfs(int)':
printer.cpp:85:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for (int i = 0; i < d.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...