Submission #648888

# Submission time Handle Problem Language Result Execution time Memory
648888 2022-10-08T16:40:16 Z Spade1 Type Printer (IOI08_printer) C++14
10 / 100
26 ms 3316 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;

vector<string> v, v2;
vector<char> ans;
int pre[N];

void solve() {
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        v.pb(s);
    }

    sort(v.begin(), v.end());

    int l = 0, mx = 0;
    for (int i = 0; i < n; ++i)
        if (v[i].size() > mx)
            l = i, mx = v[i].size();

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < v[i].size(); ++j)
            if (v[i][j] == v[l][j]) pre[i]++;
            else break;

    for (int j = 0; j <= 20; ++j) {
        for (int i = 0; i < n; ++i) {
            if (pre[i] == j) v2.pb(v[i]);
        }
    }
    for (int i = 1; i < n; ++i) {
        pre[i] = 0;
        for (int j = 0; j < min(v[i].size(), v[i-1].size()); ++j) {
            if (v[i][j] == v[i-1][j]) pre[i]++;
            else break;
        }
    }
    for (auto i : v2[0]) ans.pb(i);
    ans.pb('P');
    for (int i = 1; i < n; ++i) {
        for (int j = pre[i]; j < v2[i-1].size(); ++j) ans.pb('-');
        for (int j = pre[i]; j < v2[i].size(); ++j) ans.pb(v2[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:29:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |         if (v[i].size() > mx)
      |             ~~~~~~~~~~~~^~~~
printer.cpp:33:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for (int j = 0; j < v[i].size(); ++j)
      |                         ~~^~~~~~~~~~~~~
printer.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   44 |         for (int j = 0; j < min(v[i].size(), v[i-1].size()); ++j) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:52:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for (int j = pre[i]; j < v2[i-1].size(); ++j) ans.pb('-');
      |                              ~~^~~~~~~~~~~~~~~~
printer.cpp:53:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int j = pre[i]; j < v2[i].size(); ++j) ans.pb(v2[i][j]);
      |                              ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB printed invalid word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 740 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1628 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 3288 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 3316 KB printed invalid word
2 Halted 0 ms 0 KB -