답안 #800329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800329 2023-08-01T13:26:35 Z Liudas Type Printer (IOI08_printer) C++17
100 / 100
932 ms 8296 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(), [](string a, string b){return a.size() < b.size();});
    string bzz = arr.back();
    sort(arr.begin(), arr.end(), [&](string a, string b){
         int i = 0, j = 0;
         for(; i < a.size(); i ++){if(a[i] != bzz[i]){i--;break;}}
         for(; j < b.size(); j ++){if(b[j] != bzz[j]){j--;break;}}
         if(i != j)
         return i < j;
         return a < b;
         });
    arr.push_back("");
    vector<char> brr;
    vector<string> ans;
    string temp = "P";
    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];});
    vector<char> a2;
    for(string i : ans){
        for(char j : i){
            a2.push_back(j);
        }
    }
    while(a2.back() =='-')a2.pop_back();
    cout << a2.size() << endl;
    for(char i : a2){
        cout << i << endl;
    }
    return 0;
}

Compilation message

printer.cpp: In lambda function:
printer.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |          for(; i < a.size(); i ++){if(a[i] != bzz[i]){i--;break;}}
      |                ~~^~~~~~~~~~
printer.cpp:17:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |          for(; j < b.size(); j ++){if(b[j] != bzz[j]){j--;break;}}
      |                ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         while(k < brr.size() && k < i.size() && brr[k] == i[k]){
      |               ~~^~~~~~~~~~~~
printer.cpp:28:35: 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(k < brr.size() && k < i.size() && brr[k] == i[k]){
      |                                 ~~^~~~~~~~~~
printer.cpp:40:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int j = k; j < i.size(); j ++){
      |                        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 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 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 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 Correct 2 ms 340 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 596 KB Output is correct
2 Correct 18 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 784 KB Output is correct
2 Correct 118 ms 1312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 1636 KB Output is correct
2 Correct 50 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 336 ms 3560 KB Output is correct
2 Correct 763 ms 7288 KB Output is correct
3 Correct 441 ms 5056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 3224 KB Output is correct
2 Correct 932 ms 8296 KB Output is correct
3 Correct 478 ms 5568 KB Output is correct
4 Correct 872 ms 8060 KB Output is correct