# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
546863 | ussef_abdallah | Type Printer (IOI08_printer) | C++14 | 28 ms | 2032 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int common(string &x, string &y) {
int mn = min(x.length(), y.length());
int cnt = 0;
for (int i = 0; i < mn; i++) {
if (x[i] == y[i])
cnt++;
else
break;
}
return cnt;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<string> a(n);
string longest = "";
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i].length() > longest.length())
longest = a[i];
}
sort(a.begin(), a.end(), [&](string &x, string &y) {
int commonX = common(x, longest);
int commonY = common(y, longest);
if (commonX == commonY)
return x < y;
return commonX < commonY;
});
string cur = "";
int curPtr = 0;
for (string &s : a) {
int sPtr = 0;
while (curPtr < cur.length() && sPtr < s.length()
&& cur[curPtr] == s[sPtr]) {
curPtr++;
sPtr++;
}
int toRemove = cur.length() - 1;
while (toRemove >= curPtr) {
cur.pop_back();
toRemove--;
cout << "-" << '\n';
}
while (sPtr < s.length()) {
cout << s[sPtr] << "\n";
cur += s[sPtr];
sPtr++;
}
cout << "P" << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |