# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
116713 | 2019-06-13T15:53:19 Z | tselmegkh | Type Printer (IOI08_printer) | C++14 | 163 ms | 98552 KB |
#include<bits/stdc++.h> using namespace std; #define INF 1e9 #define MAX 100005 #define xx first #define yy second #define pb push_back #define mp make_pair #define ull long long #define FOR(i,a,b) for(int i=a;i<=b;i++) #define nl '\n' #define zai <<' '<< #define all(a) a.begin(),a.end() typedef vector<int> vi; typedef pair<int,int> ii; typedef vector<ii> vii; int total; struct Trie{ bool islast; bool isleaf; Trie *next[26]; Trie(){ for(int i=0;i<26;i++){ next[i]=NULL; islast=0; isleaf=0; } } }; void insert(Trie* root,string str,int sz){ for(int i=0;i<sz;i++){ if(root->next[str[i]-'a']==NULL){ root->next[str[i]-'a']=new Trie(); total+=2; } root=root->next[str[i]-'a']; } root->isleaf=1; } void longestmark(Trie* root,string word){ for(int i=0;i<word.size();i++){ root->next[word[i]-'a']->islast=1; root=root->next[word[i]-'a']; } } void Print(Trie* root){ for(int i=0;i<26;i++){ if(root->next[i]!=NULL && !root->next[i]->islast){ cout << char(i+'a') << nl; if(root->next[i]->isleaf){ cout << "P" << nl; } Print(root->next[i]); cout << "-" << nl; } } } int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; string word,longest=""; cin >> n; Trie *root=new Trie(); int printtimes=n; while(n--){ cin >> word; if(word.size()>longest.size()){ longest=word; } insert(root,word,word.size()); } longestmark(root,longest); cout << total-longest.size()+printtimes << nl; Print(root); for(int i=0;i<longest.size();i++){ cout << longest[i] << nl; Print(root->next[longest[i]-'a']); if(root->next[longest[i]-'a']->isleaf){ cout << "P" << nl; } root=root->next[longest[i]-'a']; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 512 KB | Output is correct |
2 | Correct | 3 ms | 1152 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1792 KB | Output is correct |
2 | Correct | 5 ms | 2304 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 5888 KB | Output is correct |
2 | Correct | 22 ms | 12408 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 14592 KB | Output is correct |
2 | Correct | 11 ms | 3328 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 67 ms | 36216 KB | Output is correct |
2 | Correct | 137 ms | 82936 KB | Output is correct |
3 | Correct | 76 ms | 42716 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 60 ms | 28336 KB | Output is correct |
2 | Correct | 163 ms | 98552 KB | Output is correct |
3 | Correct | 83 ms | 48508 KB | Output is correct |
4 | Correct | 139 ms | 93020 KB | Output is correct |