# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
322618 | 2020-11-15T02:57:57 Z | mglstew | Type Printer (IOI08_printer) | C++17 | 161 ms | 98668 KB |
#include <bits/stdc++.h> #define MOD 1000000007 #define ff first #define ss second #define pb push_back #define ll long long #define N 100005 #define ccin cin >> #define ccout cout << using namespace std; int ans = 0; struct Node{ int last; int is; Node *next[26]; Node(){ last = false; is = false; for(int i = 0; i < 26; i++){ next[i] = NULL; } } } *root = new Node; void insert(Node *root, string s){ for(int i = 0; i < s.size(); i++){ int index = s[i] - 'a'; if(root -> next[index] == NULL){ root -> next[index] = new Node; ans++; } root = root -> next[index]; } root -> last = 1; } void search(Node *root, string s){ for(int i = 0; i < s.size(); i++){ int index = s[i] - 'a'; root = root -> next[index]; root -> is = 1; } root -> last = 1; } void Print(Node *root){ for(int i = 0; i < 26; i++){ if(root -> next[i] != NULL && !root -> next[i] -> is){ ccout char(i + 'a')<< '\n'; if(root -> next[i] -> last){ ccout "P" << '\n'; } Print(root -> next[i]); ccout "-" << '\n'; } } } int n; string st; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ccin n; for(int i = 1; i <= n; i++) { string s; ccin s; insert(root, s); if(s.size() > st.size()) st = s; } search(root, st); ccout ans * 2 + n - st.size() << '\n'; Print(root); for(int i = 0; i < st.size(); i++){ ccout st[i] << '\n'; Print(root -> next[st[i] - 'a']); if(root -> next[st[i] - 'a'] -> last){ ccout "P" << '\n'; } root = root -> next[st[i] - 'a']; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 2 ms | 1132 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1900 KB | Output is correct |
2 | Correct | 4 ms | 2288 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 5868 KB | Output is correct |
2 | Correct | 22 ms | 12396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 14572 KB | Output is correct |
2 | Correct | 11 ms | 3436 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 36332 KB | Output is correct |
2 | Correct | 133 ms | 83052 KB | Output is correct |
3 | Correct | 74 ms | 42732 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 28396 KB | Output is correct |
2 | Correct | 161 ms | 98668 KB | Output is correct |
3 | Correct | 83 ms | 48552 KB | Output is correct |
4 | Correct | 139 ms | 93164 KB | Output is correct |