Submission #958641

# Submission time Handle Problem Language Result Execution time Memory
958641 2024-04-06T09:24:59 Z steveonalex Type Printer (IOI08_printer) C++17
0 / 100
29 ms 19396 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
// mt19937_64 rng(69);
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }

template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }


int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n; cin >> n;
    vector<string> a(n);

    for(int i = 0; i<n; ++i) cin >> a[i];

    string ma = "";
    for(string i: a){
        if (ma.size() < i.size()) ma = i;
    }

    vector<int> debuff(ma.size());
    for(int i = 0; i<ma.size(); ++i) debuff[i] = ma[i] - 'a' + 1;

    for(string &i: a){
        for(int j = 0; j < i.size(); ++j){
            int digit = i[j] - 'a';
            digit = (digit - debuff[j] + 26) % 26;
            i[j] = digit + 'a';
        }
    }

    sort(ALL(a));

    for(string &i: a){
        for(int j = 0; j < i.size(); ++j){
            int digit = i[j] - 'a';
            digit = (digit + debuff[j]) % 26;
            i[j] = digit + 'a';
        }
    }

    vector<string> ans;
    for(char c: a[0]) ans.push_back(string(1, c));
    ans.push_back("P");
    for(int i = 1; i<n; ++i){
        int lcp = 0;
        for(int j = 0; j < min(a[i-1].size(), a[i].size()); ++j){
            if (a[i-1][j] != a[i][j]) break;
            lcp++;
        }
        for(int j = a[i-1].size() - 1; j>=lcp; --j){
            ans.push_back("-");
        }
        for(int j = lcp; j<a[i].size(); ++j) 
            ans.push_back(string(1, a[i][j]));

        ans.push_back("P");
    }

    cout << ans.size() << "\n";
    printArr(ans, "\n");

    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:62:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0; i<ma.size(); ++i) debuff[i] = ma[i] - 'a' + 1;
      |                    ~^~~~~~~~~~
printer.cpp:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int j = 0; j < i.size(); ++j){
      |                        ~~^~~~~~~~~~
printer.cpp:75:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         for(int j = 0; j < i.size(); ++j){
      |                        ~~^~~~~~~~~~
printer.cpp:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   87 |         for(int j = 0; j < min(a[i-1].size(), a[i].size()); ++j){
      |                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:94:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for(int j = lcp; j<a[i].size(); ++j)
      |                          ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 984 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3024 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 9424 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 19396 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 18192 KB Expected EOF
2 Halted 0 ms 0 KB -