답안 #800263

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800263 2023-08-01T12:52:52 Z Liudas Type Printer (IOI08_printer) C++17
40 / 100
776 ms 7564 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<string> arr(N);
    for(string &i : arr)cin >> i;
    sort(arr.begin(), arr.end());
    arr.push_back("");
    vector<char> brr;
    vector<string> ans;
    string temp = "P";
    vector<char> a2, a3;
    for(string i : arr){
        int k = 0;
        while(k < brr.size() && k < i.size() && brr[k] == i[k]){
            k++;
        }
        int t = brr.size();
        for(int j = k; j < t; j ++){
            temp += "-";
            brr.pop_back();
        }
        if(k == 0){
            ans.push_back(temp);
            temp = "";
        }
        for(int j = k; j < i.size(); j ++){
            brr.push_back(i[j]);
            temp += i.substr(j, 1);
        }
        temp += "P";
    }
    ans.erase(ans.begin());
    map<string, int> len;
    for(string i : ans){
        int t = count(i.begin(), i.begin() + i.rfind('P'), '-');
        int tt = count(i.begin(), i.end(), 'P');
        int ttt = i.rfind('P') -  2 * t - tt + 1;
        len[i] = ttt;
    }
    sort(ans.begin(), ans.end(), [&](string a, string b){return len[a] < len[b];});
    for(string i : ans){
        for(char j : i){
            a2.push_back(j);
        }
    }
    while(a2.back() =='-')a2.pop_back();
    temp = "P";
    ans.clear();
    brr.clear();
    sort(arr.begin(), arr.end(),[](string a, string b){return a > b;});
    for(string i : arr){
        int k = 0;
        while(k < brr.size() && k < i.size() && brr[k] == i[k]){
            k++;
        }
        int t = brr.size();
        for(int j = k; j < t; j ++){
            temp += "-";
            brr.pop_back();
        }
        if(k == 0){
            ans.push_back(temp);
            temp = "";
        }
        for(int j = k; j < i.size(); j ++){
            brr.push_back(i[j]);
            temp += i.substr(j, 1);
        }
        temp += "P";
    }
    ans.erase(ans.begin());
    len.clear();
    for(string i : ans){
        int t = count(i.begin(), i.begin() + i.rfind('P'), '-');
        int tt = count(i.begin(), i.end(), 'P');
        int ttt = i.rfind('P') -  2 * t - tt + 1;
        len[i] = ttt;
    }
    sort(ans.begin(), ans.end(), [&](string a, string b){return len[a] < len[b];});
    for(string i : ans){
        for(char j : i){
            a3.push_back(j);
        }
    }
    while(a3.back() =='-')a3.pop_back();
    if(a2.size() > a3.size())swap(a2,a3);
    cout << a2.size() << endl;
    for(char i : a2){
        cout << i << endl;
    }
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:20:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         while(k < brr.size() && k < i.size() && brr[k] == i[k]){
      |               ~~^~~~~~~~~~~~
printer.cpp:20:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         while(k < brr.size() && k < i.size() && brr[k] == i[k]){
      |                                 ~~^~~~~~~~~~
printer.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int j = k; j < i.size(); j ++){
      |                        ~~^~~~~~~~~~
printer.cpp:59:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         while(k < brr.size() && k < i.size() && brr[k] == i[k]){
      |               ~~^~~~~~~~~~~~
printer.cpp:59:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         while(k < brr.size() && k < i.size() && brr[k] == i[k]){
      |                                 ~~^~~~~~~~~~
printer.cpp:71:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int j = k; j < i.size(); j ++){
      |                        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 868 KB Output is correct
2 Incorrect 120 ms 1380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 140 ms 1804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 3836 KB Output is correct
2 Correct 776 ms 7564 KB Output is correct
3 Incorrect 456 ms 5176 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 303 ms 3500 KB Output isn't correct
2 Halted 0 ms 0 KB -