Submission #588709

# Submission time Handle Problem Language Result Execution time Memory
588709 2022-07-03T22:15:28 Z Bench0310 Type Printer (IOI08_printer) C++17
100 / 100
51 ms 7304 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> s(n);
    array<int,2> m={0,0};
    for(int i=0;i<n;i++)
    {
        cin >> s[i];
        m=max(m,{int(s[i].size()),i});
    }
    vector<pair<int,string>> v(n);
    for(int i=0;i<n;i++)
    {
        int c=-1;
        while(c+1<(int)s[i].size()&&s[i][c+1]==s[m[1]][c+1]) c++;
        v[i]={c+1,s[i]};
    }
    sort(v.begin(),v.end());
    string now;
    string res;
    for(auto [c,t]:v)
    {
        int len=-1;
        while(len+1<int(min(now.size(),t.size()))&&now[len+1]==t[len+1]) len++;
        res+=string((int)now.size()-(len+1),'-');
        for(int i=len+1;i<(int)t.size();i++) res+=t[i];
        res+='P';
        now=t;
    }
    cout << res.size() << "\n";
    for(char c:res) cout << c << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 452 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 724 KB Output is correct
2 Correct 8 ms 1392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1636 KB Output is correct
2 Correct 8 ms 1796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3240 KB Output is correct
2 Correct 42 ms 6252 KB Output is correct
3 Correct 29 ms 5224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3188 KB Output is correct
2 Correct 51 ms 7304 KB Output is correct
3 Correct 31 ms 5996 KB Output is correct
4 Correct 46 ms 7116 KB Output is correct