Submission #892832

#TimeUsernameProblemLanguageResultExecution timeMemory
892832LCJLYType Printer (IOI08_printer)C++14
10 / 100
30 ms3284 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl; typedef pair<int,int>pii; typedef pair<pii,pii>pi2; pii sz2[30]; void solve(){ int n; cin >> n; string arr[n]; int sz=100; for(int x=0;x<n;x++){ cin >> arr[x]; sz=min(sz,(int)arr[x].length()); } vector<char>ans; int ptr=-1; for(int x=0;x<sz;x++){ bool amos=true; for(int y=1;y<n;y++){ if(arr[y][x]!=arr[y-1][x]) amos=false; } if(amos) ans.push_back(arr[0][x]); else break; ptr=x; } ptr++; //remove prefix vector<string>storage[30]; for(int x=0;x<n;x++){ arr[x]=arr[x].substr(ptr,(int)arr[x].length()-ptr); if((int)arr[x].length()==0) continue; int index=arr[x][0]-'a'; storage[index].push_back(arr[x]); sz2[index].first=max(sz2[index].first,(int)arr[x].length()); } for(int x=0;x<30;x++){ sz2[x].second=x; sort(storage[x].begin(),storage[x].end()); } sort(sz2,sz2+30); string last=""; for(int x=0;x<30;x++){ int index=sz2[x].second; for(auto it:storage[index]){ int target=-1; int mini=min((int)it.length(),(int)last.length()); for(int y=0;y<mini;y++){ if(it[y]==last[y]) target=y; else break; } while((int)last.length()>target+1){ ans.push_back('-'); last.pop_back(); } for(int y=target+1;y<(int)it.length();y++){ ans.push_back(it[y]); } ans.push_back('P'); last=it; } } cout << ans.size() << "\n"; for(auto it:ans){ cout << it << "\n"; } } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); //freopen("in.txt", "r", stdin); int t=1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...