제출 #1136753

#제출 시각아이디문제언어결과실행 시간메모리
1136753Theo830상형문자열 (IOI24_hieroglyphs)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "hieroglyphs.h"
vector<int> ucs(std::vector<int> a, std::vector<int> b){
    vector<int>ans;
    map<ll,ll>mp1,mp2;
    map<ll,vector<ll> >ex,ex2;
    ll w = 0;
    set<ll>E;
    for(auto x:a){
        E.insert(x);
        mp1[x]++;
        ex[x].pb(w);
        w++;
    }
    w = 0;
    for(auto x:b){
        E.insert(x);
        mp2[x]++;
        ex2[x].pb(w);
        w++;
    }
    vector<int>A,B;
    vector<int>posi,posi2;
    ll z = 0;
    posi.pb(-1);
    posi2.pb(-1);
    for(auto x:a){
        if(mp1[x] <= mp2[x]){
            A.pb(x);
            posi.pb(z);
        }
        z++;
    }
    z = 0;
    ll q = 0;
    for(auto x:b){
        if(mp2[x] < mp1[x]){
            B.pb(x);
        }
        if(q < A.size() && A[q] == x){
            posi2.pb(z);
            q++;
        }
        z++;
    }
    ll last = a.size();
    ll pos = b.size()-1;
    bool ok = q == (ll)A.size();
    while(!B.empty() && ok){
        bool ivra = 0;
        ll t;
        while(!ex[B.back()].empty() && ex[B.back()].back() >= last){
          ex[B.back()].pop_back();
        }
        if(!ex[B.back()].empty() && ex[B.back()].back() > posi.back()){
          ivra = 1;
          t = ex[B.back()].back();
        }
        bool iv = 0;
        while(!ex2[B.back()].empty() && ex2[B.back()].back() > pos){
          ex2[B.back()].pop_back();
        }
        if(!ex2[B.back()].empty() && ex2[B.back()].back() > posi2.back()){
          iv = 1;
        }
        if(ivra && iv){
            last = t;
            ans.pb(B.back());
            while(pos >= 0 && ans.back() != b[pos]){
                pos--;
            }
            pos--;
            B.pop_back();
        }
        else if(!A.empty()){
            last = posi.back();
            posi.pop_back();
            posi2.pop_back();
            ans.pb(A.back());
            while(pos >= 0 && ans.back() != b[pos]){
                pos--;
            }
            pos--;
            A.pop_back();
        }
        else{
            ok = 0;
        }
    }
    while(!A.empty()){
        ans.pb(A.back());
        A.pop_back();
    }
    reverse(all(ans));
    pos = 0;
    for(auto x:a){
        if(pos < ans.size() && ans[pos] == x){
            pos++;
        }
    }
    ok &= pos == (ll)ans.size();
    pos = 0;
    for(auto x:b){
        if(pos < ans.size() && ans[pos] == x){
            pos++;
        }
    }
    ok &= pos == (ll)ans.size();
    set<ll>x1,x2,x3;
    map<ll,ll>last1,last2,last3;
    ll p = 0;
    for(auto x:a){
        last1[x] = p;
        p++;
        x1.insert(x);
    }
    p = 0;
    for(auto x:b){
        last2[x] = p;
        p++;
        x2.insert(x);
    }
    p = 0;
    for(auto x:ans){
        last3[x] = p;
        p++;
        x3.insert(ans);
    }
    if(!ok){
        ans.clear();
        ans.pb(-1);
    }
    else{
        map<ll,ll>posi1,posi2,posi3;
        for(auto x:E){
            f(j,0,min(mp1[x],mp2[x])){
                while(a[posi1[x]] != x){
                    if(posi1[x] == last1[x]){
                        x1.erase(x);
                    }
                    posi1[x]++;
                }
                while(b[posi2[x]] != x){
                    if(posi2[x] == last2[x]){
                        x2.erase(x);
                    }
                    posi2[x]++;
                }
                while(ans[posi3[x]] != x){
                    if(posi3[x] == last3[x]){
                        x3.erase(x);
                    }
                    posi3[x]++;
                }
                if(posi1[x] == last1[x]){
                    x1.erase(x);
                }
                if(posi2[x] == last2[x]){
                    x2.erase(x);
                }
                if(posi3[x] == last3[x]){
                    x3.erase(x);
                }
                posi1[x]++;
                posi2[x]++;
                posi3[x]++;
                for(auto z:x1){
                    if(x2.count(z) && !x3.count(z)){
                        ok = 0;
                        break;
                    }
                }
            }
        }
    }
    if(!ok){
        ans.clear();
        ans.pb(-1);
    }
    return ans;
}
/*
int main() {
  int N, M;
  assert(2 == scanf("%d%d", &N, &M));
  std::vector<int> A(N), B(M);
  for (int i = 0; i < N; i++)
    assert(1 == scanf("%d", &A[i]));
  for (int j = 0; j < M; j++)
    assert(1 == scanf("%d", &B[j]));
  fclose(stdin);

  std::vector<int> R = ucs(A, B);

  int T = (int)R.size();
  printf("%d\n", T);
  for (int i = 0; i < T; i++)
    printf("%s%d", (i == 0 ? "" : " "), R[i]);
  printf("\n");
  fclose(stdout);

  return 0;
}

*/

컴파일 시 표준 에러 (stderr) 메시지

hieroglyphs.cpp: In function 'std::vector<int> ucs(std::vector<int>, std::vector<int>)':
hieroglyphs.cpp:150:18: error: no matching function for call to 'std::set<int>::insert(std::vector<int>&)'
  150 |         x3.insert(ans);
      |         ~~~~~~~~~^~~~~
In file included from /usr/include/c++/11/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:87,
                 from hieroglyphs.cpp:1:
/usr/include/c++/11/bits/stl_set.h:566:9: note: candidate: 'template<class _InputIterator> void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  566 |         insert(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/11/bits/stl_set.h:566:9: note:   template argument deduction/substitution failed:
hieroglyphs.cpp:150:18: note:   candidate expects 2 arguments, 1 provided
  150 |         x3.insert(ans);
      |         ~~~~~~~~~^~~~~
In file included from /usr/include/c++/11/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:87,
                 from hieroglyphs.cpp:1:
/usr/include/c++/11/bits/stl_set.h:509:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<int>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<int>, int>::rebind<int>; typename _Alloc::value_type = int; std::set<_Key, _Compare, _Alloc>::value_type = int]'
  509 |       insert(const value_type& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_set.h:509:32: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const value_type&' {aka 'const int&'}
  509 |       insert(const value_type& __x)
      |              ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_set.h:518:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<int>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<int>, int>::rebind<int>; typename _Alloc::value_type = int; std::set<_Key, _Compare, _Alloc>::value_type = int]'
  518 |       insert(value_type&& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_set.h:518:27: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::set<int>::value_type&&' {aka 'int&&'}
  518 |       insert(value_type&& __x)
      |              ~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_set.h:546:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = int]'
  546 |       insert(const_iterator __position, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_set.h:546:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/11/bits/stl_set.h:551:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = int]'
  551 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_set.h:551:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/11/bits/stl_set.h:578:7: note: candidate: 'void std::set<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  578 |       insert(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_set.h:578:43: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::initializer_list<int>'
  578 |       insert(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_set.h:598:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::insert_return_type std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::node_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::insert_return_type = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::insert_return_type; std::set<_Key, _Compare, _Alloc>::node_type = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::node_type]'
  598 |       insert(node_type&& __nh)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_set.h:598:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::set<int>::node_type&&' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::node_type&&'}
  598 |       insert(node_type&& __nh)
      |              ~~~~~~~~~~~~^~~~
/usr/include/c++/11/bits/stl_set.h:603:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::node_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::node_type = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::node_type]'
  603 |       insert(const_iterator __hint, node_type&& __nh)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_set.h:603:7: note:   candidate expects 2 arguments, 1 provided