Submission #581208

# Submission time Handle Problem Language Result Execution time Memory
581208 2022-06-22T11:32:55 Z LucaIlie Type Printer (IOI08_printer) C++17
100 / 100
78 ms 5572 KB
#include <bits/stdc++.h>

#define MAX_N 25000
#define MAX_LEN 20

using namespace std;

char lit[MAX_LEN];
int lcp[MAX_N];
string s[MAX_N];
vector <char> sol;

bool comp( int i, char a, char b ) {
    if ( lit[i] == a )
        return 0;
    if ( lit[i] == b )
        return 1;
    return a < b;
}

bool cmp( const string &a, const string &b ) {
    int i;

    i = 0;
    while ( i < a.size() && i < b.size() && a[i] == b[i] )
        i++;

    return (i == a.size() || (i < b.size() && comp( i, a[i], b[i] )));
}

int main() {
    int n, maxLen, i, l, p;

    cin >> n;
    for ( i = 0; i < n; i++ )
        cin >> s[i];

    maxLen = 0;
    p = 0;
    for ( i = 0; i < n; i++ ) {
        if ( (int)s[i].size() > maxLen ) {
            maxLen = s[i].size();
            p = i;
        }
    }

    for ( i = 0; i < s[p].size(); i++ )
        lit[i] = s[p][i];

    sort( s, s + n, cmp );

    for ( i = 1; i < n; i++ ) {
        while ( lcp[i] < s[i - 1].size() && lcp[i] < s[i].size() && s[i - 1][lcp[i]] == s[i][lcp[i]] )
            lcp[i]++;
    }

    l = 0;
    for ( i = 0; i < n; i++ ) {
        while ( l > lcp[i] ) {
            sol.push_back( '-' );
            l--;
        }
        while ( l < s[i].size() ) {
            sol.push_back( s[i][l] );
            l++;
        }
        sol.push_back( 'P' );
    }

    cout << sol.size() << "\n";
    for ( char o: sol )
        cout << o << "\n";

    return 0;
}

Compilation message

printer.cpp: In function 'bool cmp(const string&, const string&)':
printer.cpp:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     while ( i < a.size() && i < b.size() && a[i] == b[i] )
      |             ~~^~~~~~~~~~
printer.cpp:25:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     while ( i < a.size() && i < b.size() && a[i] == b[i] )
      |                             ~~^~~~~~~~~~
printer.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     return (i == a.size() || (i < b.size() && comp( i, a[i], b[i] )));
      |             ~~^~~~~~~~~~~
printer.cpp:28:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     return (i == a.size() || (i < b.size() && comp( i, a[i], b[i] )));
      |                               ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for ( i = 0; i < s[p].size(); i++ )
      |                  ~~^~~~~~~~~~~~~
printer.cpp:53:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         while ( lcp[i] < s[i - 1].size() && lcp[i] < s[i].size() && s[i - 1][lcp[i]] == s[i][lcp[i]] )
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~
printer.cpp:53:52: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         while ( lcp[i] < s[i - 1].size() && lcp[i] < s[i].size() && s[i - 1][lcp[i]] == s[i][lcp[i]] )
      |                                             ~~~~~~~^~~~~~~~~~~~~
printer.cpp:63:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         while ( l < s[i].size() ) {
      |                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 2 ms 1092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1104 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1236 KB Output is correct
2 Correct 11 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1616 KB Output is correct
2 Correct 11 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2376 KB Output is correct
2 Correct 65 ms 4424 KB Output is correct
3 Correct 47 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2116 KB Output is correct
2 Correct 78 ms 5572 KB Output is correct
3 Correct 57 ms 4224 KB Output is correct
4 Correct 74 ms 5568 KB Output is correct