Submission #966684

#TimeUsernameProblemLanguageResultExecution timeMemory
966684vjudge1Type Printer (IOI08_printer)C++14
10 / 100
37 ms2624 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; string maxi=""; int pref(string a) { int cnt=0; while (a[cnt] == maxi[cnt]) { cnt++; } return cnt; } static bool cmp(string&a,string&b) { int x=pref(a); int y=pref(b); if (a == maxi) { return false; } if (b == maxi) { return true; } if (x != y) { return x<y; } return a.size() < b.size(); } int main() { ll n; cin >> n; vector<string> p(n); for (int i=0;i<n;i++) { cin >> p[i]; if (p[i].size() > maxi.size()) { maxi = p[i]; } } sort(p.begin(),p.end(),cmp); string curr=""; string ans=""; for (int i=0;i<n;i++) { while (curr.size() != 0 && curr != p[i].substr(0,curr.size())) { ans+="-"; curr.pop_back(); } ans+=p[i].substr(curr.size(),p[i].size()-curr.size()); curr=p[i]; ans+="P"; } n = ans.size(); cout << n<<'\n'; for (int i=0;i<n;i++) { cout << ans[i] <<'\n'; } return 0; }
#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...