# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
705892 | 2023-03-05T15:24:31 Z | assem_albitar | Type Printer (IOI08_printer) | C++14 | 159 ms | 100580 KB |
#include <bits/stdc++.h> #define ll long long #define ld long double #define mod 1000000007 #define mxe(v) *max_element(v.begin(), v.end()) #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(),v.rend() #define F first #define S second #define pi pair<ll,ll> #define assem ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define yes cout<<"YES"<<endl; #define no cout<<"NO"<<endl; using namespace std; const int N=400200; const double PI=3.1415926535897932384626433; const double eps = 1e-9; string getString() { char c[(int)21]; //scanf(" %c",&a[i]); scanf("%s", c); return c; //string x = getString(); } ///printf("%d\n",); ///scanf("%d",&); ///cout.precision(10); ///puts("")string vector<char> ans; int n; vector<string> v; struct trie { int cnt,c; trie* child[26]; trie() { cnt=c=0; memset(child,0,sizeof child); } void add(int i,int j) { if(j==v[i].size()) { c++; cnt=j; return; } if(child[v[i][j]-'a']==0)child[v[i][j]-'a']=new trie(); child[v[i][j]-'a']->add(i,j+1); if(child[v[i][j]-'a']->cnt>cnt)cnt=child[v[i][j]-'a']->cnt; } void get() { if(c) { ans.push_back('P'); } multiset<pair<int,char>> a; for(char i='a'; i<='z'; i++) { if(child[i-'a']!=0) { a.insert({child[i-'a']->cnt,i}); } } for(auto it=a.begin();it!=a.end();it++) { ans.push_back(it->S); child[it->S-'a']->get(); ans.push_back('-'); } return; } }; int main() { scanf("%d",&n); trie* root=new trie(); for(int i=0; i<n; i++) { string q; q=getString(); v.push_back(q); root->add(i,0); } root->get(); while(ans.back()=='-')ans.pop_back(); printf("%d\n",(int)ans.size()); for(int i=0; i<ans.size(); i++) { printf("%c\n",ans[i]); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1748 KB | Output is correct |
2 | Incorrect | 4 ms | 2260 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 5972 KB | Output is correct |
2 | Correct | 19 ms | 12752 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 15052 KB | Output is correct |
2 | Correct | 8 ms | 3660 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 37448 KB | Output is correct |
2 | Correct | 117 ms | 84576 KB | Output is correct |
3 | Correct | 67 ms | 44516 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 29644 KB | Output is correct |
2 | Correct | 159 ms | 100580 KB | Output is correct |
3 | Correct | 76 ms | 50416 KB | Output is correct |
4 | Correct | 131 ms | 95120 KB | Output is correct |