답안 #546864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546864 2022-04-08T17:09:53 Z ussef_abdallah Type Printer (IOI08_printer) C++14
10 / 100
32 ms 2244 KB
#include <bits/stdc++.h>

using namespace std;

int common(string &x, string &y) {
    int mn = min(x.length(), y.length());
    int cnt = 0;
    for (int i = 0; i < mn; i++) {
        if (x[i] == y[i])
            cnt++;
        else
            break;
    }
    return cnt;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> a(n);
    string longest = "";
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i].length() > longest.length())
            longest = a[i];
    }
    sort(a.begin(), a.end(), [&](string &x, string &y) {
        int commonX = common(x, longest);
        int commonY = common(y, longest);
        if (commonX == commonY)
            return x < y;
        return commonX < commonY;
    });
    string cur = "";
    int curPtr = 0;
    vector<char> ans;
    for (string &s : a) {
        int sPtr = 0;
        while (curPtr < cur.length() && sPtr < s.length()
               && cur[curPtr] == s[sPtr]) {

            curPtr++;
            sPtr++;
        }
        int toRemove = cur.length() - 1;
        while (toRemove >= curPtr) {
            cur.pop_back();
            toRemove--;
            ans.push_back('-');
        }
        while (sPtr < s.length()) {
            ans.push_back(s[sPtr]);
            cur += s[sPtr];
            sPtr++;
        }
        ans.push_back('P');
    }
    cout << ans.size() << '\n';
    for (char &c : ans) {
        cout << c << "\n";
    }
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         while (curPtr < cur.length() && sPtr < s.length()
      |                ~~~~~~~^~~~~~~~~~~~~~
printer.cpp:41:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         while (curPtr < cur.length() && sPtr < s.length()
      |                                         ~~~~~^~~~~~~~~~~~
printer.cpp:53:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         while (sPtr < s.length()) {
      |                ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Incorrect 1 ms 316 KB printed invalid word
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 596 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 1140 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 2244 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 2096 KB printed invalid word
2 Halted 0 ms 0 KB -