답안 #581106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581106 2022-06-22T09:15:37 Z LucaIlie Type Printer (IOI08_printer) C++17
30 / 100
66 ms 4916 KB
#include <bits/stdc++.h>

#define MAX_N 25000
#define MAX_LEN 20

using namespace std;

int lcp[MAX_N - 1];
string s[MAX_N];
vector <char> sol;

int main() {
    int n, minLen, first, last, i, j, l;
    bool cresc;

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

    sort( s, s + n );

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

    minLen = MAX_LEN + 1;
    last = -1;
    cresc = true;
    for ( i = 0; i < n; i++ ) {
        if ( 2 * lcp[i] - (int)s[i].size() < minLen ) {
            minLen = 2 * lcp[i] - (int)s[i].size();
            last = i;
            cresc = true;
        }
        if ( 2 * lcp[(i - 1 + n) % n] - (int)s[i].size() < minLen ) {
            minLen = 2 * lcp[i] - (int)s[i].size();
            last = i;
            cresc = false;
        }
    }

    if ( cresc ) {
        first = (last + 1) % n;
        l = 0;
        for ( int k = 0; k < n; k++ ) {
            i = (first + k) % n;
            j = (i - 1 + n) % n;
            while ( l > lcp[j] ) {
                sol.push_back( '-' );
                l--;
            }
            while ( l < s[i].size() ) {
                sol.push_back( s[i][l] );
                l++;
            }
            sol.push_back( 'P' );
        }
    } else {
        first = (last - 1 + n) % n;
        l = 0;
        for ( int k = 0; k < n; k++ ) {
            i = (first - k + n) % n;
            j = (i - 1 + n) % n;
            while ( l > lcp[j] ) {
                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 'int main()':
printer.cpp:25:19: 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 ( l < s[i].size() && l < s[j].size() && s[i][l] == s[j][l] )
      |                 ~~^~~~~~~~~~~~~
printer.cpp:25:38: 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 ( l < s[i].size() && l < s[j].size() && s[i][l] == s[j][l] )
      |                                    ~~^~~~~~~~~~~~~
printer.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |             while ( l < s[i].size() ) {
      |                     ~~^~~~~~~~~~~~~
printer.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             while ( l < s[i].size() ) {
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Incorrect 1 ms 1088 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1364 KB Output is correct
2 Incorrect 11 ms 1620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 1744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 2632 KB Output is correct
2 Correct 66 ms 4916 KB Output is correct
3 Incorrect 42 ms 3912 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 2244 KB Output isn't correct
2 Halted 0 ms 0 KB -