Submission #966684

# Submission time Handle Problem Language Result Execution time Memory
966684 2024-04-20T08:16:12 Z vjudge1 Type Printer (IOI08_printer) C++14
10 / 100
37 ms 2624 KB
#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 time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 2624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 2552 KB Output isn't correct
2 Halted 0 ms 0 KB -