# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155619 | 2019-09-29T09:33:53 Z | karma | Type Printer (IOI08_printer) | C++14 | 72 ms | 37252 KB |
#include<bits/stdc++.h> #define Task "test" #define pb emplace_back using namespace std; const int N = 25001; const int nAlpha = 26; string s[N]; int n, res, Max; struct TNode { int finish; TNode* chil[nAlpha]; } *root; typedef TNode* PNode; PNode Add() { ++res; PNode ptr = new TNode(); ptr -> finish = 0; for(int i = 0; i < nAlpha; ++i) ptr -> chil[i] = NULL; return ptr; } void Ins(string s) { PNode ptr = root; for(int i = 0; i < int(s.size()); ++i) { s[i] -= 'a'; if(ptr -> chil[s[i]] == NULL) ptr -> chil[s[i]] = Add(); ptr = ptr -> chil[s[i]]; } ++ptr -> finish; } void Trace(PNode ptr, int depth, bool keep, char letter) { if(ptr != root) cout << letter << '\n'; for(int i = 0; i < nAlpha; ++i) { if(ptr -> chil[i] == NULL) continue; if(!keep) Trace(ptr -> chil[i], depth + 1, 0, char('a' + i)); else if(i != s[Max][depth] - 'a') Trace(ptr -> chil[i], depth + 1, 0, char('a' + i)); } if(keep && depth < int(s[Max].size())) { if(ptr -> chil[s[Max][depth] - 'a']) Trace(ptr -> chil[s[Max][depth] - 'a'], depth + 1, 1, s[Max][depth]); } if(ptr -> finish) cout << "P\n"; if(!keep) cout << "-\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); if(fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } cin >> n; s[Max = 0] = ""; res = -1; root = Add(); for(int i = 1; i <= n; ++i) { cin >> s[i]; Ins(s[i]); if(int(s[Max].size()) < int(s[i].size())) Max = i; } res = res * 2 + n - s[Max].size(); cout << res << '\n'; Trace(root, 0, 1, 'a'); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1272 KB | Output is correct |
2 | Correct | 3 ms | 1144 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1148 KB | Output is correct |
2 | Correct | 3 ms | 1148 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1144 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1144 KB | Output is correct |
2 | Incorrect | 3 ms | 1144 KB | printed invalid word |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1272 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 2556 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 14 ms | 6776 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 35 ms | 15340 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 72 ms | 37252 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 63 ms | 29060 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |