# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
445760 | 2021-07-19T13:57:43 Z | dxz05 | Type Printer (IOI08_printer) | C++14 | 1000 ms | 83592 KB |
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #define SZ(x) (int)(x).size() const int MAXN = 1e6 + 3e2; string str[MAXN]; int next_free = 2; int trie[MAXN][26], term[MAXN]; int mx[MAXN]; void add(int ind, int val, string &s){ int v = 1; for (int i = 0; i < s.size(); i++){ int x = s[i] - 'a'; if (trie[v][x] == 0) trie[v][x] = next_free++; v = trie[v][x]; mx[v] = max(mx[v], val); } term[v] = 1; } vector<char> ans; int n, cnt = 0; void solve(int v){ if (term[v]){ cnt++; ans.push_back('P'); if (cnt == n){ cout << ans.size() << endl; for (char c : ans) cout << c << endl; exit(0); } } int best = 0, ind = -1; for (int i = 0; i < 26; i++){ if (trie[v][i] != 0){ if (mx[trie[v][i]] > best){ best = mx[trie[v][i]]; ind = i; } } } for (int i = 0; i < 26; i++){ if (trie[v][i] != 0 && ind != i){ ans.push_back('a' + i); solve(trie[v][i]); ans.push_back('-'); } } if (ind != -1){ ans.push_back('a' + ind); solve(trie[v][ind]); ans.push_back('-'); } } int main(){ //ios_base::sync_with_stdio(false); //cin.tie(nullptr); cout.tie(nullptr); scanf("%d", &n); int ind = 0; for (int i = 1; i <= n; i++){ char c[25]; scanf("%s", &c); int len = strlen(c); str[i].resize(len); for (int j = 0; j < len; j++) str[i][j] = c[j]; //cout << str[i] << endl; if (str[i].size() > str[ind].size()) ind = i; } string longest = str[ind]; for (int i = 1; i <= n; i++){ int j = 0; while (j < str[i].size() && str[i][j] == longest[j]) j++; add(i, j, str[i]); //cout << j << ' ' << str[i] << endl; } solve(1); return 0; } /** 3 print the poem */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 31564 KB | Output is correct |
2 | Correct | 17 ms | 31624 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 31620 KB | Output is correct |
2 | Correct | 16 ms | 31616 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 31616 KB | Output is correct |
2 | Correct | 20 ms | 31616 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 31564 KB | Output is correct |
2 | Correct | 16 ms | 31580 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 31608 KB | Output is correct |
2 | Correct | 29 ms | 31960 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 32312 KB | Output is correct |
2 | Correct | 45 ms | 32588 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 103 ms | 34592 KB | Output is correct |
2 | Correct | 198 ms | 38112 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 237 ms | 39132 KB | Output is correct |
2 | Correct | 79 ms | 33476 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 560 ms | 50684 KB | Output is correct |
2 | Execution timed out | 1094 ms | 75492 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 512 ms | 46404 KB | Output is correct |
2 | Execution timed out | 1082 ms | 83592 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |