Submission #1193781

#TimeUsernameProblemLanguageResultExecution timeMemory
1193781layla_abdallaType Printer (IOI08_printer)C++20
0 / 100
39 ms37308 KiB
#include <iostream> #include <vector> #include <queue> #include <cstring> #include <map> #include<set> #include<string> #include<iomanip> #include <algorithm> #include <unordered_set> #include <cmath> #include <numeric> #include<unordered_map> using namespace std; #define LAYLA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long #define pb push_back #define p push #define el '\n' const ll mod = 1000000007; const ll INF = 1e9+5; const ll N =5e5+5; ll mult(ll a, ll c) { return((a % mod) * (c % mod)) % mod; } ll fast_power(ll base, ll power) { if (power == 1)return base; ll halfpower = (fast_power(base, power / 2)); ll ret = mult(halfpower, halfpower); if (power % 2)ret = mult(ret, base); return ret; } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll add (int a, int b){ return (a+b)%mod; } struct TrieNode { TrieNode* child[26] = {}; bool end = false; }; TrieNode* root = new TrieNode; vector<char> v; void insert(const string& word) { TrieNode* node = root; for (char c : word) { int idx = c - 'a'; if (!node->child[idx]) { node->child[idx] = new TrieNode; } node = node->child[idx]; } node->end = true; } void dfs(TrieNode* node, string& current) { if (node->end) v.push_back('P'); for (int i = 0; i < 26; i++) { if (node->child[i]) { char c = 'a' + i; v.push_back(c); current.push_back(c); dfs(node->child[i], current); v.push_back('-'); current.pop_back(); } } } int main() { LAYLA int n; cin >> n; vector<string> words(n); for (int i=0; i<n ; i++) cin >> words[i]; sort(words.begin(), words.end()); for (int i=0; i<n ; i++) insert(words[i]); string temp; dfs(root, temp); cout << v.size() << el; for (char c : v) cout << c << el; }
#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...