Submission #1026241

# Submission time Handle Problem Language Result Execution time Memory
1026241 2024-07-17T18:22:00 Z ach00 Type Printer (IOI08_printer) C++14
10 / 100
1000 ms 2516 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> choices;
    vector<char> cprint;
    int pc = 0;
    for(auto &a : words) cin >> a;
    sort(words.begin(), words.end(), cmp);
    int itp = 0;
    while(pc != n) {
        while(cprint.size() != words[itp].size()) {
            choices.push_back(words[itp][cprint.size()]);
            cprint.push_back(words[itp][cprint.size()]);
        }
        choices.push_back('P');
        pc++;
        if(pc == n) break;
        printed[itp] = true;
        int mx_prf = -1;
        int mx_id = -1;
        for(int i = 0; i < n; i++) {
            if(printed[i]) continue;
            int cnt = 0;
            for(int j = 0; j < min(words[i].size(), cprint.size()); j++) {
                if(words[i][j] == cprint[j]) cnt++;
                else break;
            }
            if(cnt > mx_prf) {
                mx_prf = cnt;
                mx_id = i;
            }
        }
        itp = mx_id;
        while(cprint.size() != mx_prf) {
            cprint.pop_back();
            choices.push_back('-');
        }
    }
    cout << choices.size() << '\n';
    for(auto &c : choices) {
        cout << c << '\n';
    }
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:32:30: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   32 |             for(int j = 0; j < min(words[i].size(), cprint.size()); j++) {
      |                            ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:42:29: warning: comparison of integer expressions of different signedness: 'std::vector<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |         while(cprint.size() != mx_prf) {
      |               ~~~~~~~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 1256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 720 ms 2516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 1620 KB Time limit exceeded
2 Halted 0 ms 0 KB -