Language: C++

#include<iostream>
#include<vector>
#include<bitset>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  // ここでストリームに obj を書き込みます。
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

void input(vector<vector<int>>& v,int k,li a,int flag){
  rep(i,64){
    if(flag!=a%2){
      v[i][k]=2-flag;
    }
    a/=2;
  }
}

int calc(vector<vector<int>>& sgy,vector<int>& s,vector<int>& t,
         vector<int>& u,vector<int>& v){
  if(df) print(s,t,"u",u,"v",v);
  int f1=0,f2=0,f;
  for(int x:u) f1|=x;
  for(int x:v) f2|=x;
  f=f1*f2*(f1+f2);
  if(df) print(f1,f2,f);
  if(f!=0 and f!=2 and f!=16) return 1;
  int n=s.size();
  vector<int> unu,unv;
  rep(i,n){
    if(!u[i]) unu.push_back(i);
    rep(j,n) sgy[i][j]=u[i]-1;
  }
  rep(j,n){
    if(!v[j]) unv.push_back(j);
    rep(i,n) if(sgy[i][j]==-1) sgy[i][j]=v[j]-1;
  }
  
  if(df){
    rep(i,n) print(sgy[i]);
    print("u:",unu);
    print("v:",unv);
  }
  if(unu.size()==0) return 0;
  if(n==1){
    if(s[0]!=t[0])return 1;
    else sgy[0][0]=s[0];
    return 0;
  }
  if(unu.size()==1){
    int flag=1;
    int a=s[unu[0]];  // aがあればok
    for(int j:unv){
      int b=t[j];    // bがあればok
      rep(i,n){
        if(i==unu[0])continue;
        if(a==sgy[i][j]) flag=0;
        if(b==sgy[i][j]){
          sgy[unu[0]][j]=a;
          if(df)print("[",unu[0],j,"]=",a);
          flag=0;
          break;
        }
      }
      if(sgy[unu[0]][j]==-1) sgy[unu[0]][j]=b;
    }
    return flag;
  }
  
  
  if(unv.size()==1){
    int flag=1;
    int b=t[unv[0]];  // bがあればok
    for(int i:unu){
      int a=s[i];    // aがあればok
      rep(j,n){
        if(j==unv[0])continue;
        if(b==sgy[i][j]) flag=0;
        if(a==sgy[i][j]){
          sgy[i][unv[0]]=b;
          flag=0;
          break;
        }
      }
      if(sgy[i][unv[0]]==-1) sgy[i][unv[0]]=b;
    }
    return flag;
  }
  rep(i,unu.size())
    rep(j,unv.size())
    sgy[unu[i]][unv[j]]=(i+j)%2;
  return 0;
}


int main(){
  int n; cin >>n;
  vector<int> s(n),t(n);
  vector<vector<int>> u(64,vector<int>(n,0)),v(64,vector<int>(n,0));
  li dm=1;
  rep(i,n) cin >> s[i];
  rep(i,n) cin >> t[i];
  rep(i,n){
    li a; cin >>a; if(dm<a) dm=a;
    input(u,i,a,s[i]);
  }
  int ord=3; while(dm){ord++;dm/=2;}
  ord=min(64,ord); ord=64;
  rep(i,n){
    li a; cin >>a;
    input(v,i,a,t[i]);
  } // 
  if(df){
    print(s,t);                 // 
    rep(i,ord) print(u[i]);
    rep(i,ord) print(v[i]);
  }

  vector<vector<li>> ans(n,vector<int> (n,0));
  vector<vector<int>> sgy(n,vector<int> (n,-1));
  
  li b=1;
  rep(i,ord){
    if(calc(sgy,s,t,u[i],v[i])){
      print(-1);
      return 0;
    }
    if(df) rep(i,n) print(sgy[i]);
    rep(row,n) rep(col,n) ans[row][col]+=sgy[row][col]*b;
    if(df) print(b);
    b*=2;
  }
  for(auto x:ans) print(x);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:131:45: error: no matching function for call to 'std::vector<std::vector<long long int> >::vector(int&, std::vector<int>)'
  131 |   vector<vector<li>> ans(n,vector<int> (n,0));
      |                                             ^
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:707:9: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]'
  707 |         vector(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:707:9: note:   template argument deduction/substitution failed:
a.cc:131:45: note:   deduced conflicting types for parameter '_InputIterator' ('int' and 'std::vector<int>')
  131 |   vector<vector<li>> ans(n,vector<int> (n,0));
      |                                             ^
/usr/include/c++/14/bits/stl_vector.h:678:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; allocator_type = std::allocator<std::vector<long long int> >]'
  678 |       vector(initializer_list<value_type> __l,
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:678:43: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<std::vector<long long int> >'
  678 |       vector(initializer_list<value_type> __l,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:659:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; std::__type_identity_t<_Alloc> = std::allocator<std::vector<long long int> >]'
  659 |       vector(vector&& __rv, const __type_identity_t<allocator_type>& __m)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:659:23: note:   no known conversion for argument 1 from 'int' to 'std::vector<std::vector<long long int> >&&'
  659 |       vector(vector&& __rv, const __type_identity_t<allocator_type>& __m)
      |              ~~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_vector.h:640:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::false_type) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; allocator_type = std::allocator<std::vector<long long int> >; std::false_type = std::false_type]'
  640 |       vector(vector&& __rv, const allocator_type& __m, false_type)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:640:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_vector.h:635:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::true_type) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; allocator_type = std::allocator<std::vector<long long int> >; std::true_type = std::true_type]'
  635 |       vector(vector&& __rv, const allocator_type& __m, true_type) noexcept
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:635:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_vector.h:624:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; std::__type_identity_t<_Alloc> = std::allocator<std::vector<long long int> >]'
  624 |       vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:624:28: note:   no known conversion for argument 1 from 'int' to 'const std::vector<std::vector<long long int> >&'
  624 |       vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
      |              ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:620:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]'
  620 |       vector(vector&&) noexcept = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:620:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:601:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]'
  601 |       vector(const vector& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:601:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:569:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; size_type = long unsigned int; value_type = std::vector<long long int>; allocator_type = std::allocator<std::vector<long long int> >]'
  569 |       vector(size_type __n, const value_type& __value,
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:569:47: note:   no known conversion for argument 2 from 'std::vector<int>' to 'const std::vector<std::vector<long long int> >::value_type&' {aka 'const std::vector<long long int>&'}
  569 |       vector(size_type __n, const value_type& __value,
      |                             ~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_vector.h:556:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; size_type = long unsigned int; allocator_type = std::allocator<std::vector<long long int> >]'
  556 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:556:51: note:   no known conversion for argument 2 from 'std::vector<int>' to 'const std::vector<std::vector<long long int> >::allocator_type&' {aka 'const std::allocator<std::vector<long long int> >&'}
  556 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |                             ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:542:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; allocator_type = std::allocator<std::vector<long long int> >]'
  542 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:542:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:531:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]'
  531 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:531:7: note:   candidate expects 0 arguments, 2 provided
a.cc: In instantiation of 'void print(const T&, const Ts& ...) [with T = std::vector<int>; Ts = {std::vector<int, std::allocator<int> >, char [2], std::vector<int, std::allocator<int> >, char [2], std::vector<int, std::allocator<int> >}]':
a.cc:33:15:   required from here
   33 |   if(df) print(s,t,"u",u,"v",v);
      |          ~~~~~^~~~~~~~~~~~~~~~~
a.cc:9:79: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'const std::vector<int>')
    9 | template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
      |                                                                          ~~~~~^~~~
In file included from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:116:36: note:   no known conversion for argument 1 from 'const std::vector<int>' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]'
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:125:32: note:   no known conversion for argument 1 from 'const std::vector<int>' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  135 |       operator<<(ios_base& (*__pf) (ios_base&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:135:30: note:   no known conversi