# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
390200 | 2021-04-15T14:44:11 Z | parsabahrami | Type Printer (IOI08_printer) | C++17 | 26 ms | 22788 KB |
/* There's someone in my head but it's not me */ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 1e5 + 10; int nxt[26][N], M[N], dp[N], H[N], n, tim, tar; char S[N]; vector<char> ret; void addtrie(char* x) { int v = 0; for (int i = 0; x[i]; i++) { int c = x[i] - 'a'; if (!nxt[c][v]) nxt[c][v] = ++tim, H[tim] = H[v] + 1; v = nxt[c][v]; } M[v] = 1; } void preDFS(int v) { dp[v] = (v == tar); for (int i = 0; i < 26; i++) if (nxt[i][v]) { preDFS(nxt[i][v]); dp[v] |= dp[nxt[i][v]]; } } void DFS(int v) { if (M[v]) ret.push_back('P'); int u = -1; for (int i = 0; i < 26; i++) if (nxt[i][v] && !dp[nxt[i][v]]) ret.push_back('a' + i), DFS(nxt[i][v]), ret.push_back('-'); else if (nxt[i][v]) u = i; if (~u) ret.push_back('a' + u), DFS(nxt[u][v]); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%s", S + 1), addtrie(S + 1); tar = max_element(H, H + N) - H; preDFS(0); DFS(0); printf("%d\n", SZ(ret)); for (char c : ret) printf("%c\n", c); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 460 KB | Output is correct |
2 | Correct | 2 ms | 844 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1232 KB | Output is correct |
2 | Correct | 5 ms | 1484 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 3404 KB | Output is correct |
2 | Correct | 21 ms | 6972 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 8116 KB | Output is correct |
2 | Correct | 9 ms | 2124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 22 ms | 22788 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 23 ms | 22740 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |