Submission #924970

#TimeUsernameProblemLanguageResultExecution timeMemory
924970vjudge1Type Printer (IOI08_printer)C++17
0 / 100
45 ms23892 KiB
#include<bits/stdc++.h> using namespace std; #ifdef ONPC #include"debug.h" #else #define debug(...) 42 #endif #define endl '\n' #define ll long long #define pii pair<int,int> #define F first #define S second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int mod = 1e9 + 7; const int MAXN = 1e6 + 15; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; bool good_set = 1; int trie[MAXN][26]; int Data[MAXN]; int dep[MAXN]; int node_cnt = 1; void insert(string s){ int node = 1; for (char c : s){ if (!trie[node][c - 'a']){ trie[node][c - 'a'] = ++node_cnt; } node = trie[node][c - 'a']; } Data[node]++; return; } int cnt = 0; int n; void calc_dep(int node){ int mx = 0; for (int i = 0; i < 26; i++){ if (trie[node][i]){ calc_dep(trie[node][i]); ckmax(mx, dep[trie[node][i]]); } } dep[node] = mx + 1; } void solve(int node){ if (Data[node]){ cout << 'P' << endl; cnt++; if (cnt == n) exit(0); } vector<int> children; for (int i = 0; i < 26; i++){ if (trie[node][i]){ children.pb(i); } } sort(all(children), [&](int l, int r){ return dep[trie[node][l]] < dep[trie[node][r]]; }); for (int child : children){ cout << char(child + 'a') << endl; solve(trie[node][child]); cout << '-' << endl; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; i++){ string s; cin >> s; insert(s); } calc_dep(1); solve(1); }
#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...