Submission #957382

#TimeUsernameProblemLanguageResultExecution timeMemory
957382bmh123456789asdfType Printer (IOI08_printer)C++14
20 / 100
16 ms16984 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 25010; int child[N][26], dp[N], depth[N], par[N], stop[N]; vector<pair<int,char>> adj[N]; vector<char> ans; int cnt = 0, n, Node; string s[N]; void insertword(string word,int num) { int node = 0, cur = 0; for(auto k : word) { if(child[node][k - 'a'] == 0) { child[node][k - 'a'] = ++cnt; adj[node].push_back({cnt, k}); par[cnt] = node; } node = child[node][k - 'a']; } stop[node]++; while(node != 0) depth[par[node]] = max(depth[par[node]], depth[node] + 1), node = par[node]; } bool mmb(pair<int,char> a,pair<int,char> b) { return depth[a.first] < depth[b.first]; } void DFS(int u) { for(auto v : adj[u]) { while(Node != u) Node = par[Node], ans.push_back('-'); Node = child[Node][v.second - 'a']; ans.push_back(v.second); DFS(v.first); } if(stop[u]) stop[u]-- ,ans.push_back('P'); } int32_t main() { // freopen("test.inp", "r" ,stdin); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) { cin >> s[i]; insertword(s[i], i); } vector<pair<int,char>> v; for(int i = 0; i <= cnt; i++) sort(adj[i].begin(), adj[i].end(), mmb); DFS(0); cout << ans.size() <<'\n'; for(auto k : ans) cout << k<<'\n'; }

Compilation message (stderr)

printer.cpp: In function 'void insertword(std::string, long long int)':
printer.cpp:14:19: warning: unused variable 'cur' [-Wunused-variable]
   14 |     int node = 0, cur = 0;
      |                   ^~~
#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...