Submission #510072

# Submission time Handle Problem Language Result Execution time Memory
510072 2022-01-14T16:19:57 Z Yazan_Alattar Type Printer (IOI08_printer) C++14
30 / 100
65 ms 11000 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
#include <assert.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 200007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int n;
string s[M], cur;
vector <char> ans;
vector < vector <char> > v[30];

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> s[i];
    sort(s + 1, s + n + 1);
    for(int i = 1; i <= n; ++i){
        int cnt = 0;
        while(cur.size() && (cur.size() > s[i].size() || s[i].substr(0, (int)cur.size()) != cur)) cur.pop_back(), ans.pb('-'), ++cnt;
        if(cur.empty()){
            v[cnt].pb(ans);
            ans.clear();
        }
        for(int j = cur.size(); j < s[i].size(); ++j){
            ans.pb(s[i][j]);
            cur += s[i][j];
        }
        ans.pb('P');
    }
    int cnt = 0;
    for(int i = 0; i < s[n].size(); ++i) ans.pb('-'), ++cnt;
    v[cnt].pb(ans);
    ans.clear();
    for(int i = 1; i <= 21; ++i)
        for(auto j : v[i])
            for(auto k : j)
                ans.pb(k);
    while(ans.back() == '-') ans.pop_back();
    cout << ans.size() << endl;
    for(auto i : ans) cout << i << endl;
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:45:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(int j = cur.size(); j < s[i].size(); ++j){
      |                                 ~~^~~~~~~~~~~~~
printer.cpp:52:22: 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 i = 0; i < s[n].size(); ++i) ans.pb('-'), ++cnt;
      |                    ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6476 KB Output is correct
2 Correct 3 ms 6476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6560 KB Output is correct
2 Correct 5 ms 6476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6476 KB Output is correct
2 Incorrect 4 ms 6576 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6476 KB Output is correct
2 Correct 4 ms 6580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 6572 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 6604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6852 KB Output is correct
2 Incorrect 14 ms 7196 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 7364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 8408 KB Output is correct
2 Correct 65 ms 11000 KB Output is correct
3 Incorrect 38 ms 9592 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 7892 KB Output isn't correct
2 Halted 0 ms 0 KB -