답안 #720340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
720340 2023-04-08T03:52:04 Z Yell0 Type Printer (IOI08_printer) C++17
컴파일 오류
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(1,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:37: error: no matching function for call to 'std::vector<std::__cxx11::basic_string<char> >::push_back(int, __gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type&)'
   48 |       ss.push_back(1,w[i][ct.size()]);
      |                                     ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >; std::vector<_Tp, _Alloc>::value_type = std::__cxx11::basic_string<char>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >; std::vector<_Tp, _Alloc>::value_type = std::__cxx11::basic_string<char>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note:   candidate expects 1 argument, 2 provided