# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
468520 | 2021-08-28T15:56:21 Z | mariowong | Type Printer (IOI08_printer) | C++14 | 117 ms | 31164 KB |
#include <bits/stdc++.h> #define hmod (long long)1223334444555553 using namespace std; int n,len,mx,indx,cnt,now,tmp; string s[25005]; char node[500005]; bool build,gg; vector <int> edge[500005]; bool p[500005]; vector <char> ans; void dfs(int x){ if (x != 0) ans.push_back(node[x]); if (p[x]) ans.push_back('P'); for (int i=0;i<edge[x].size();i++){ dfs(edge[x][i]); } ans.push_back('-'); } int main(){ ios::sync_with_stdio(false); //freopen("typ7b.in","r",stdin); cin >> n; for (int i=1;i<=n;i++){ now=0; cin >> s[i]; len=s[i].length(); if (len > mx){ mx=len; indx=i; } for (int j=0;j<len;j++){ build=true; for (int k=0;k<edge[now].size();k++){ if (node[edge[now][k]] == s[i][j]){ now=edge[now][k]; build=false; break; } } if (build){ edge[now].push_back(++cnt); node[cnt]=s[i][j]; now=cnt; } } p[now]=true; } len=s[indx].length(); now=0; for (int i=0;i<len;i++){ for (int j=0;j<edge[now].size();j++){ if (node[edge[now][j]] == s[indx][i]){ tmp=edge[now][j]; edge[now].erase(edge[now].begin()+j); edge[now].push_back(tmp); now=tmp; break; } } } dfs(0); cout << (int)ans.size()-mx-1 << "\n"; for (int i=0;i<(int)ans.size()-mx-1;i++){ cout << ans[i] << "\n"; } return 0; } /* 8 xxvebmc ixhvdhcjxon hsspmkly labfaryosskugbkiuffd yerx mhgpafawzhnt eejzatjmnqxctn n */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 12748 KB | Output is correct |
2 | Correct | 8 ms | 12768 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 12748 KB | Output is correct |
2 | Correct | 8 ms | 12740 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 12796 KB | Output is correct |
2 | Correct | 8 ms | 12848 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 12748 KB | Output is correct |
2 | Correct | 9 ms | 12768 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 12772 KB | Output is correct |
2 | Correct | 10 ms | 13004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 13004 KB | Output is correct |
2 | Correct | 10 ms | 13132 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 13792 KB | Output is correct |
2 | Correct | 22 ms | 14992 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 15296 KB | Output is correct |
2 | Correct | 15 ms | 13744 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 19156 KB | Output is correct |
2 | Correct | 105 ms | 28240 KB | Output is correct |
3 | Correct | 58 ms | 21188 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 17344 KB | Output is correct |
2 | Correct | 117 ms | 31164 KB | Output is correct |
3 | Correct | 64 ms | 22376 KB | Output is correct |
4 | Correct | 101 ms | 30164 KB | Output is correct |