Submission #720339

# Submission time Handle Problem Language Result Execution time Memory
720339 2023-04-08T03:51:03 Z Yell0 Type Printer (IOI08_printer) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MN=25002;
int N,ans=0;
string w[MN];
vector<string> ss;
map<string,int> wpos;

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  cin>>N;
  for(int i=1;i<=N;++i) cin>>w[i];
  sort(w+1,w+1+N);
  int mx=0,mxi=0;
  for(int i=1;i<=N;++i) {
    wpos[w[i]]=i;
    if((int)w[i].size()>mx) {
      mx=w[i].size();
      mxi=i;
    }
  }
  int endp=N;
  for(int i=1;i<=(int)w[mxi].size();++i)
    for(int j=1;j<=N;++j) {
      if((int)w[j].size()<i) continue;
      if(w[j].substr(0,i)==w[mxi].substr(0,i)) wpos[w[j]]=++endp;
    }
  sort(w+1,w+1+N,[](string a,string b) {return wpos[a]<wpos[b];});
  string ct="";
  for(int i=1;i<=N;++i) {
    string cw=w[i];
    while(ct.size()>cw.size()) {
      ct.pop_back();
      ++ans;
      ss.push_back("-");
    }
    while(ct.size()<cw.size()) cw.pop_back();
    while(ct!=cw) {
      ct.pop_back();
      cw.pop_back();
      ++ans;
      ss.push_back("-");
    }
    while(ct.size()<w[i].size()) {
      ++ans;
      ss.push_back(string(w[i][ct.size()]));
      ct.push_back(w[i][ct.size()]);
    }
    ++ans;
    ss.push_back("P");
  }
  cout<<ans<<'\n';
  for(string s:ss) cout<<s<<'\n';
  return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:48:42: error: no matching function for call to 'std::__cxx11::basic_string<char>::basic_string(__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type&)'
   48 |       ss.push_back(string(w[i][ct.size()]));
      |                                          ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from printer.cpp:1:
/usr/include/c++/10/bits/basic_string.h:650:2: note: candidate: 'template<class _Tp, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Tp&, const _Alloc&) [with _Tp = _Tp; <template-parameter-2-2> = <template-parameter-1-2>; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  650 |  basic_string(const _Tp& __t, const _Alloc& __a = _Alloc())
      |  ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:650:2: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 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/type_traits: In substitution of 'template<bool _Cond, class _Tp> using enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = void]':
/usr/include/c++/10/bits/basic_string.h:117:8:   required by substitution of 'template<class _CharT, class _Traits, class _Alloc> template<class _Tp, class _Res> using _If_sv = std::enable_if_t<std::__and_<std::is_convertible<const _Tp&, std::basic_string_view<_CharT, _Traits> >, std::__not_<std::is_convertible<const _Tp*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>*> >, std::__not_<std::is_convertible<const _Tp&, const _CharT*> > >::value, _Res> [with _Tp = char; _Res = void; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
/usr/include/c++/10/bits/basic_string.h:648:30:   required from here
/usr/include/c++/10/type_traits:2554:11: error: no type named 'type' in 'struct std::enable_if<false, void>'
 2554 |     using enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from printer.cpp:1:
/usr/include/c++/10/bits/basic_string.h:639:2: note: candidate: 'template<class _Tp, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Tp&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _Tp = _Tp; <template-parameter-2-2> = <template-parameter-1-2>; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  639 |  basic_string(const _Tp& __t, size_type __pos, size_type __n,
      |  ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:639:2: note:   template argument deduction/substitution failed:
printer.cpp:48:42: note:   candidate expects 4 arguments, 1 provided
   48 |       ss.push_back(string(w[i][ct.size()]));
      |                                          ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from printer.cpp:1:
/usr/include/c++/10/bits/basic_string.h:625:9: note: candidate: 'template<class _InputIterator, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(_InputIterator, _InputIterator, const _Alloc&) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  625 |         basic_string(_InputIterator __beg, _InputIterator __end,
      |         ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:625:9: note:   template argument deduction/substitution failed:
printer.cpp:48:42: note:   candidate expects 3 arguments, 1 provided
   48 |       ss.push_back(string(w[i][ct.size()]));
      |                                          ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from printer.cpp:1:
/usr/include/c++/10/bits/basic_string.h:587:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  587 |       basic_string(basic_string&& __str, const _Alloc& __a)
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:587:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/10/bits/basic_string.h:583:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  583 |       basic_string(const basic_string& __str, const _Alloc& __a)
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:583:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/10/bits/basic_string.h:579:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::initializer_list<_Tp>, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  579 |       basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:579:45: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'std::initializer_list<char>'
  579 |       basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/basic_string.h:552:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  552 |       basic_string(basic_string&& __str) noexcept
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:552:35: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'std::__cxx11::basic_string<char>&&'
  552 |       basic_string(basic_string&& __str) noexcept
      |                    ~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/10/bits/basic_string.h:540:7: note: candidate: 'template<class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, _CharT, const _Alloc&) [with <template-parameter-2-1> = <template-parameter-1-1>; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  540 |       basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:540:7: note:   template argument deduction/substitution failed:
printer.cpp:48:42: note:   candidate expects 3 arguments, 1 provided
   48 |       ss.push_back(string(w[i][ct.size()]));
      |                                          ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from printer.cpp:1:
/usr/include/c++/10/bits/basic_string.h:525:7: note: candidate: 'template<class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with <template-parameter-2-1> = <template-parameter-1-1>; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  525 |       basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:525:7: note:   template argument deduction/substitution failed:
printer.cpp:48:42: note:   cannot convert 'w[i].std::__cxx11::basic_string<char>::operator[](ct.std::__cxx11::basic_string<char>::size())' (type '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'}) to type 'const char*'
   48 |       ss.push_back(string(w[i][ct.size()]));
      |                                          ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from printer.cpp:1:
/usr/include/c++/10/bits/basic_string.h:510:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]'
  510 |       basic_string(const _CharT* __s, size_type __n,
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:510:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/10/bits/basic_string.h:492:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]'
  492 |       basic_string(const basic_string& __str, size_type __pos,
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:492:7: note:   candidate expects 4 arguments, 1 provided
/usr/include/c++/10/bits/basic_string.h:476:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]'
  476 |       basic_string(const basic_string& __str, size_type __pos,
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:476:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/10/bits/basic_string.h:461:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]'
  461 |       basic_string(const basic_string& __str, size_type __pos,
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:461:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/10/bits/basic_string.h:448:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  448 |       basic_string(const basic_string& __str)
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:448:40: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'const std::__cxx11::basic_string<char>&'
  448 |       basic_string(const basic_string& __str)
      |                    ~~~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/10/bits/basic_string.h:440:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  440 |       basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:440:34: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'const std::allocator<char>&'
  440 |       basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
      |                    ~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/basic_string.h:431:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  431 |       basic_string()
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:431:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/10/bits/basic_string.h:145:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::__sv_wrapper, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  145 |       basic_string(__sv_wrapper __svw, const _Alloc& __a)
      |       ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:145:7: note:   candidate expects 2 arguments, 1 provided