답안 #1026264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026264 2024-07-17T18:36:53 Z ach00 Type Printer (IOI08_printer) C++14
100 / 100
53 ms 8168 KB
#include <bits/stdc++.h>
using namespace std;

bool cmp(const string &s1, const string &s2) {
    return s1.size() < s2.size();
}

int main() {
    int n; cin >> n;
    vector<string> words(n);    
    vector<bool> printed(n, false);
    vector<char> cprint;
    int pc = 0;
    for(auto &a : words) cin >> a;
    sort(words.begin(), words.end(), cmp);
    string biggest_word = words[n-1];
    vector<char> ans;
    vector<pair<int, string>> prefixsort;
    for(int i = 0; i < n-1; i++) {
        int cnt = 0;
        for(int j = 0; j < words[i].size(); j++) {
            if(words[i][j] == biggest_word[j]) cnt++;
            else break;
        }
        prefixsort.push_back({cnt, words[i]});
    }
    prefixsort.push_back({biggest_word.size(), biggest_word});
    sort(prefixsort.begin(), prefixsort.end());
    for(int i = 0; i < n; i++) {
        string word = prefixsort[i].second;
        int cnt = 0;
        for(int j = 0; j < cprint.size(); j++) {
            if(cprint[j] == word[j]) cnt++;
            else break;
        }
        while(cprint.size() != cnt) {
            ans.push_back('-');
            cprint.pop_back();
        }
        for(int j = cnt; j < word.size(); j++) {
            cprint.push_back(word[j]);
            ans.push_back(word[j]);
        }
        ans.push_back('P');
    }
    cout << ans.size() << '\n';
    for(auto &s : ans) {
        cout << s << '\n';
    }
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:21:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for(int j = 0; j < words[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~~~
printer.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int j = 0; j < cprint.size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~
printer.cpp:36:29: warning: comparison of integer expressions of different signedness: 'std::vector<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |         while(cprint.size() != cnt) {
      |               ~~~~~~~~~~~~~~^~~~~~
printer.cpp:40:28: 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 = cnt; j < word.size(); j++) {
      |                          ~~^~~~~~~~~~~~~
printer.cpp:13:9: warning: unused variable 'pc' [-Wunused-variable]
   13 |     int pc = 0;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 360 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 828 KB Output is correct
2 Correct 8 ms 1344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1620 KB Output is correct
2 Correct 9 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 3360 KB Output is correct
2 Correct 44 ms 7276 KB Output is correct
3 Correct 32 ms 5608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 3272 KB Output is correct
2 Correct 53 ms 8164 KB Output is correct
3 Correct 40 ms 6376 KB Output is correct
4 Correct 53 ms 8168 KB Output is correct