Submission #1040948

# Submission time Handle Problem Language Result Execution time Memory
1040948 2024-08-01T12:44:26 Z ArthuroWich Type Printer (IOI08_printer) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int trie[2500][26], le[2500][26], co = 1, en[2500];
vector<char> ans;
void insert(string s) {
    int n = 0;
    for (int i = 0; i < s.length(); i++) { 
        char c = s[i];
        le[n][c-'a'] = max(le[n][c-'a'], s.length()-i);
        if (!trie[n][c-'a']) {
            trie[n][c-'a'] = co;
            co++;
        }
        n = trie[n][c-'a'];
    }
    en[n] = 1;
}
void dfs(int a) {
    if (en[a]) {
        ans.push_back('P');
    }
    vector<pair<int, int>> v;
    for (int i = 0; i < 26; i++) {
        if (trie[a][i]) {
            v.push_back({le[a][i], i});
        }
    }
    sort(v.begin(), v.end());
    for (auto [_, i] : v) {
        ans.push_back((char)(i+'a'));
        dfs(trie[a][i]);
        ans.push_back('-');
    }
}
void solve() {
    int n;
    cin >> n;   
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        insert(s);
    }
    dfs(0);
    while(!ans.empty() && ans.back() == '-') {
        ans.pop_back();
    }
    cout << ans.size() << endl;
    for (char c : ans) {
        cout << c << endl;
    }
}
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    t = 1;
    while(t--) {
        solve();
    }
}

Compilation message

printer.cpp: In function 'void insert(std::string)':
printer.cpp:8:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i = 0; i < s.length(); i++) {
      |                     ~~^~~~~~~~~~~~
printer.cpp:10:54: error: no matching function for call to 'max(long long int&, long long unsigned int)'
   10 |         le[n][c-'a'] = max(le[n][c-'a'], s.length()-i);
      |                                                      ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from printer.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
printer.cpp:10:54: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   10 |         le[n][c-'a'] = max(le[n][c-'a'], s.length()-i);
      |                                                      ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from printer.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
printer.cpp:10:54: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   10 |         le[n][c-'a'] = max(le[n][c-'a'], s.length()-i);
      |                                                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
printer.cpp:10:54: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   10 |         le[n][c-'a'] = max(le[n][c-'a'], s.length()-i);
      |                                                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
printer.cpp:10:54: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   10 |         le[n][c-'a'] = max(le[n][c-'a'], s.length()-i);
      |                                                      ^