Submission #522227

# Submission time Handle Problem Language Result Execution time Memory
522227 2022-02-04T08:41:06 Z blue Type Printer (IOI08_printer) C++17
100 / 100
95 ms 5500 KB
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string W;

bool xcompare(string& A, string& B)
{
    return A.size() < B.size();
}

bool scompare(string& A, string& B)
{
    int a, b;
    for(a = 0; A[a] == W[a]; a++);
    for(b = 0; B[b] == W[b]; b++);
    if(a == b)
    {
        if(A == B) return 1;
        for(int i = 0; i < min(A.size(), B.size()); i++)
        {
            if(A[i] < B[i]) return 1;
            if(A[i] > B[i]) return 0;
        }
        return A.size() < B.size();
    }
    return a < b;
}
    

int main()
{
    int n;
    cin >> n;
    string S[n+1];
    for(int i = 1; i <= n; i++) cin >> S[i];
    
    sort(S+1, S+n+1, xcompare);
    W = S[n];
    sort(S+1, S+n+1, scompare);
    
    string P;
    string res;
    for(int i = 1; i <= n; i++)
    {
        while((P.length() > S[i].length()) || (S[i].substr(0, P.length()) != P))
        {
            P.pop_back();
            res += char(45);
        }
        while(P.length() < S[i].length())
        {
            P += S[i][P.length()];
            res += S[i][P.length()-1];
        }
        
        res += 'P';
    }
    cout << res.length() << '\n';
    for(char c:res) cout << c << '\n';
    
    return 0;
}

Compilation message

printer.cpp: In function 'bool scompare(std::string&, std::string&)':
printer.cpp:21:26: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   21 |         for(int i = 0; i < min(A.size(), B.size()); i++)
      |                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 3 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 588 KB Output is correct
2 Correct 13 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1120 KB Output is correct
2 Correct 12 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2140 KB Output is correct
2 Correct 76 ms 4632 KB Output is correct
3 Correct 57 ms 3760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1984 KB Output is correct
2 Correct 95 ms 5500 KB Output is correct
3 Correct 61 ms 4196 KB Output is correct
4 Correct 84 ms 5340 KB Output is correct