답안 #648768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648768 2022-10-08T07:58:06 Z Spade1 Type Printer (IOI08_printer) C++14
10 / 100
24 ms 2564 KB
#include<bits/stdc++.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;

const int N = 3e5 + 10;

int pre[N];

void solve() {
    int n; cin >> n;
    vector<string> v;
    vector<char> ans;
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        v.pb(s);
    }
    sort(v.begin(), v.end());
    for (int i = 1; i < n; ++i) {
        int cnt = 0;
        for (int j = 0; j < 20; ++j) {
            if (v[i][j] == v[i-1][j]) cnt++;
            else break;
        }
        pre[i] = cnt;
    }
    for (auto i : v[0]) ans.pb(i);
    ans.pb('P');
    for (int i = 1; i < n; ++i) {
        for (int j = pre[i]; j < v[i-1].size(); ++j) ans.pb('-');
        for (int j = pre[i]; j < v[i].size(); ++j) ans.pb(v[i][j]);
        ans.pb('P');
    }
    cout << ans.size() << '\n';
    for (auto i : ans) cout << i << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}

Compilation message

printer.cpp: In function 'void solve()':
printer.cpp:36:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (int j = pre[i]; j < v[i-1].size(); ++j) ans.pb('-');
      |                              ~~^~~~~~~~~~~~~~~
printer.cpp:37:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for (int j = pre[i]; j < v[i].size(); ++j) ans.pb(v[i][j]);
      |                              ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 1240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 2564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 2512 KB Output isn't correct
2 Halted 0 ms 0 KB -