답안 #440488

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440488 2021-07-02T10:20:12 Z dxz05 Type Printer (IOI08_printer) C++14
10 / 100
650 ms 4964 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;

#define SZ(x) (int)(x).size()

const int MAXN = 1e5 + 3e2;

string str[MAXN];

int main(){
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    int ind = 0;
    for (int i = 1; i <= n; i++){
        cin >> str[i];
        if (str[i].size() > str[ind].size()) ind = i;
    }

    string longest = str[ind];

    for (int i = 1; i <= n; i++){
        int j = 0;
        while (j < str[i].size() && j < longest.size() && str[i][j] == longest[j]) j++;
        str[i] = string(j, '{') + str[i];
    }

    sort(str + 1, str + n + 1);

    vector<char> ans;
    for (int it = 1; it <= n; it++){
        int j = 0;
        while (j < str[it].size() && str[it][j] == '{') j++;
        str[it].erase(0, j);

        string s = str[it], t = str[it - 1];

        int need = max(0, SZ(t) - SZ(s));
        while (need--) ans.push_back('-');

        int cnt = 0;
        for (int i = 0; i < min(SZ(t), SZ(s)); i++){
            if (t[i] == s[i]) cnt++; else
                break;
        }

        need = max(0, SZ(t) - cnt);
        while (need--){
            ans.push_back('-');
        }

        for (int i = cnt; i < s.size(); i++){
            ans.push_back(s[i]);
        }
        ans.push_back('P');

    }

    cout << ans.size() << endl;
    for (char c : ans) cout << c << endl;

    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         while (j < str[i].size() && j < longest.size() && str[i][j] == longest[j]) j++;
      |                ~~^~~~~~~~~~~~~~~
printer.cpp:28:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         while (j < str[i].size() && j < longest.size() && str[i][j] == longest[j]) j++;
      |                                     ~~^~~~~~~~~~~~~~~~
printer.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         while (j < str[it].size() && str[it][j] == '{') j++;
      |                ~~^~~~~~~~~~~~~~~~
printer.cpp:56:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for (int i = cnt; i < s.size(); i++){
      |                           ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3404 KB too many deletions
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3404 KB too many deletions
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 3404 KB too many deletions
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 3404 KB too many deletions
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 3520 KB too many deletions
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 100 ms 3712 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 251 ms 4080 KB too many deletions
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 650 ms 4964 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 528 ms 4464 KB too many deletions
2 Halted 0 ms 0 KB -