# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
57796 | 2018-07-16T07:13:32 Z | gnoor | Type Printer (IOI08_printer) | C++17 | 945 ms | 43152 KB |
#include <cstdio> #include <vector> #include <string> #include <algorithm> #include <iostream> #include <map> using namespace std; vector<string> tbl; vector<char> ans; map<string,int> mp; bool cmp(const string &a ,const string &b) { string x; int cur=0; while (a[cur]==b[cur]) { x.push_back(a[cur]); cur++; } string y=x; if (a[cur]) x.push_back(a[cur]); if (b[cur]) y.push_back(b[cur]); //cout << x << " " << y << " " << mp[x] << " " << mp[y] << endl; int aa=mp[x]; int bb=mp[y]; if (aa!=bb) return aa<bb; return x<y; } int main () { int n; scanf("%d",&n); string x; string y; for (int i=0;i<n;i++) { cin >> x; tbl.push_back(x); y.clear(); for (int j=0;j<(int)x.size();j++) { y.push_back(x[j]); mp[y]=max(mp[y],(int)x.size()); } } sort(tbl.begin(),tbl.end(),cmp); for (int i=0;i<(int)tbl[0].size();i++) { ans.push_back(tbl[0][i]); } ans.push_back('P'); for (int i=1;i<n;i++) { int cnt=0; while (tbl[i][cnt]==tbl[i-1][cnt]) cnt++; for (int j=0;j<(int)tbl[i-1].size()-cnt;j++) { ans.push_back('-'); } for (int j=cnt;j<(int)tbl[i].size();j++) { ans.push_back(tbl[i][j]); } ans.push_back('P'); } printf("%d\n",ans.size()); for (int i=0;i<(int)ans.size();i++) { printf("%c\n",ans[i]); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 288 KB | Output is correct |
2 | Correct | 3 ms | 356 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 356 KB | Output is correct |
2 | Correct | 3 ms | 560 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 560 KB | Output is correct |
2 | Correct | 3 ms | 560 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 560 KB | Output is correct |
2 | Correct | 3 ms | 560 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 560 KB | Output is correct |
2 | Correct | 8 ms | 840 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 1096 KB | Output is correct |
2 | Correct | 17 ms | 1368 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 2924 KB | Output is correct |
2 | Correct | 122 ms | 5628 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 201 ms | 6544 KB | Output is correct |
2 | Correct | 189 ms | 6544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 430 ms | 15784 KB | Output is correct |
2 | Correct | 727 ms | 36344 KB | Output is correct |
3 | Correct | 648 ms | 36344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 412 ms | 36344 KB | Output is correct |
2 | Correct | 945 ms | 43152 KB | Output is correct |
3 | Correct | 651 ms | 43152 KB | Output is correct |
4 | Correct | 756 ms | 43152 KB | Output is correct |