Submission #876439

# Submission time Handle Problem Language Result Execution time Memory
876439 2023-11-21T18:33:24 Z StefanL2005 Type Printer (IOI08_printer) C++14
30 / 100
26 ms 2524 KB
#include <bits/stdc++.h>
using namespace std;

struct LetterPoz{
    int poz, length;
};

bool rule(LetterPoz A, LetterPoz B)
{
    if (A.length == B.length)
        return A.poz < B.poz;
    return A.length < B.length;
}

int Similarities(string A, string B)
{
    int lA = A.length(), lB = B.length(), nr = 0;

    for (int i = 0; i < min(lA, lB); i++)
        if (A[i] == B[i])
            nr++;
        else
            break;

    return nr;
}


int main()
{
    int N;
    cin>> N;
    vector<string> To_Print(N);
    vector<char> Commands;
    for (int i = 0; i < N; i++)
        cin>> To_Print[i];

    sort(To_Print.begin(), To_Print.end());

    vector<int> MaxL(26, -1);
    vector<int> Poz(26, N);
    vector<LetterPoz> Sorted;
    
    for (int i = 0; i < N; i++)
    {
        Poz[To_Print[i][0] - 'a'] = min(Poz[To_Print[i][0] - 'a'], i);
        MaxL[To_Print[i][0] - 'a'] = max(MaxL[To_Print[i][0] - 'a'], int(To_Print[i].length()));
    }

    for (int i = 0; i < 26; i++)
    {
        if (MaxL[i] != -1)
        {
            LetterPoz A;
            A.length = MaxL[i];
            A.poz = Poz[i];

            Sorted.push_back(A);
        }
    }

    sort(Sorted.begin(), Sorted.end(), rule);
    
    string Last = "";
    for (int i = 0; i < Sorted.size(); i++)
    {
        int poz = Sorted[i].poz;
        int letter = To_Print[poz][0];

        while (poz < N && To_Print[poz][0] == letter)
        {
            int sim = Similarities(To_Print[poz], Last);

            for (int j = 0; j < Last.length()- sim; j++)
                Commands.push_back('-');
             for (int j = sim; j < To_Print[poz].length(); j++)
                Commands.push_back(To_Print[poz][j]);
            Commands.push_back('P');

            Last = To_Print[poz];
            poz++;
        }
    }

    cout<< Commands.size() << "\n";
    for (int i = 0; i < Commands.size(); i++)
        cout<< Commands[i] << "\n";
    
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:65:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<LetterPoz>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for (int i = 0; i < Sorted.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
printer.cpp:74:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             for (int j = 0; j < Last.length()- sim; j++)
      |                             ~~^~~~~~~~~~~~~~~~~~~~
printer.cpp:76:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |              for (int j = sim; j < To_Print[poz].length(); j++)
      |                                ~~^~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:86:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for (int i = 0; i < Commands.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~~
# 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 0 ms 348 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 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Output is correct
2 Incorrect 9 ms 1116 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 2524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 2352 KB Output isn't correct
2 Halted 0 ms 0 KB -