답안 #581143

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581143 2022-06-22T09:37:38 Z LucaIlie Type Printer (IOI08_printer) C++17
30 / 100
67 ms 4420 KB
#include <bits/stdc++.h>
 
#define MAX_N 25000
#define MAX_LEN 20
 
using namespace std;
 
int lcp[MAX_N];
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 - 1 + n) % n] - (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 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Incorrect 2 ms 980 KB printed invalid word
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 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 2 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1236 KB Output is correct
2 Incorrect 12 ms 1620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 1676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 2504 KB Output is correct
2 Incorrect 67 ms 4420 KB printed invalid word
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 2064 KB Output isn't correct
2 Halted 0 ms 0 KB -