# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63171 | nvmdava | Type Printer (IOI08_printer) | C++17 | 5 ms | 1032 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
struct Node{
char val;
Node *let[26];
int maxId, lon = 0, size = 0;
bool operator<(const Node* rhs) const{
if(this == NULL){
return 1;
}
return lon < rhs -> lon;
}
void sorter(){
sort(let, let + 26);
lon = let[25] -> lon + 1;
for(int i = 0;i <= 25; i++){
size += let[i] -> size;
}
size+=2;
}
} *root[26];
void insert(string s, Node* now, int i, int len){
if(i == len){
return;
}
if(now -> let[s[i] - 'a'] == NULL){
now -> let[s[i] - 'a'] = new Node;
}
now = now -> let[s[i] - 'a'];
now -> val = s[i];
insert(s, now, i + 1, len);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, i;
for(i = 0; i <= 25; i++){
root[i] = new Node;
}
cin>>n;
string s;
for(i = 1; i <= n; i++){
cin>>s;
insert(s, root[s[0] - ' a'], 1, s.size());
}
int ans = 0;
for(i = 1; i <= n; i++){
root[i] -> sorter();
ans += root[i] -> size;
}
sort(root, root + 26);
ans -= root[25] -> lon;
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |