QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#351408#8005. Crossing the BorderSolitaryDream#Compile Error//C++173.0kb2024-03-11 21:40:282024-03-11 21:40:28

Judging History

你现在查看的是最新测评结果

  • [2024-03-11 21:40:28]
  • 评测
  • [2024-03-11 21:40:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long
using pii=pair<int,int>;

const int N=22,P=998244353;

pii add(const pii &a,const pii &b)
{
    if(a.first>b.first)
        return a;
    else if(b.first>a.first)
        return b;
    else
        return {a.first,(a.second+b.second)%P};
}

int n,W;

pii o[N];

pii f[1<<N];

int sw[1<<N];

vector<pair<int,pii> > t[1<<N];

int gl[1<<(N/2)][1<<(N/2)],gr[1<<(N/2)][1<<(N/2)];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>W;
    for(int i=0;i<n;i++)
        cin>>o[i].second>>o[i].first;
    sort(o,o+n,greater<pii>());
    f[0].second=1;
    int L=n/2,R=n-n/2;
    // for(int S=0;S<(1<<R);S++)
    // {
    //     vector<pii> rw;
    //     for(int T=S;;T=(T+1)|S)
    //     {
    //         int tmp=T^S,sm=0;
    //         for(int i=0;i<n;i++)
    //             if(tmp>>i&1)
    //                 sm+=o[i].second;
    //         rw.push_back({sm,T});
    //         if(T==(1<<R)-1)
    //             break;
    //     }
    //     sort(rw.begin(),rw.end());
    //     int c=0;
    //     for(auto [x,id]:rw)
    //         gr[S][id]=++c;
    // }

    
    // for(int S=0;S<(1<<L);S++)
    // {
    //     vector<pii> rw;
    //     for(int T=S;;T=(T+1)|S)
    //     {
    //         int tmp=(T^S)<<R,sm=0;
    //         for(int i=0;i<n;i++)
    //             if(tmp>>i&1)
    //                 sm+=o[i].second;
    //         rw.push_back({sm,T});
    //         if(T==(1<<L)-1)
    //             break;
    //     }
    //     sort(rw.begin(),rw.end());
    //     int c=0;
    //     for(auto [x,id]:rw)
    //         gl[S][id]=++c;
    // }

    for(int S=1;S<(1<<n);S++)
        sw[S]=sw[S-(S&-S)]+o[__builtin_ctz(S&-S)].second;

    for(int S=0;S<(1<<n);S++)
    {
        //S + T''
        int SL=S>>R,SR=S^(SL<<R);
        for(int T=SR;;T=(T-1)&SR)
        {
            if(!T)
                break;
            int M=SL<<R|T;
            int D=T^SR;
            auto it=upper_bound(t[M].begin(),t[M].end(),W-sw[D]);
            if(it!=t[M].begin())
                f[S]=add(f[M],(--it)->second);

            if(sw[D]<=W)
                f[S]=add(f[S],{f[M].first+o[(31-__builtin_clz(D))].first,f[M].second});
        }

        //S + T'
        sort(t[S].begin(),t[S].end());
        for(int i=1;i<t[S].size();i++)
            t[S][i].second=add(t[S][i-1].second,t[S][i].second);
        //S
        int p=-1;
        for(int i=0;i<n;i++)
            if(!(S>>i&1))
            {
                p=i;
                break;
            }
        if(p==-1)
            continue;
        if(p>=R)
        {
            S|=(1<<p);
            for(int T=SL;;T=(T+1)|SL)
            {
                t[T<<R|SR].push_back({sw[T<<R],{f[S].first+o[p].first,f[S].second}});

                if(T==(1<<L)-1)
                    break;
            }
        }
    }
    cout<<f[(1<<n)-1].first<<" "<<f[(1<<n)-1].second;
}

Details

cc1plus: error: ‘::main’ must return ‘int’
In file included from /usr/include/c++/13/bits/stl_algobase.h:71,
                 from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/13/bits/predefined_ops.h: In instantiation of ‘bool __gnu_cxx::__ops::_Val_less_iter::operator()(_Value&, _Iterator) const [with _Value = const long long int; _Iterator = __gnu_cxx::__normal_iterator<std::pair<long long int, std::pair<long long int, long long int> >*, std::vector<std::pair<long long int, std::pair<long long int, long long int> > > >]’:
/usr/include/c++/13/bits/stl_algo.h:2035:14:   required from ‘_ForwardIterator std::__upper_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = __gnu_cxx::__normal_iterator<pair<long long int, pair<long long int, long long int> >*, vector<pair<long long int, pair<long long int, long long int> > > >; _Tp = long long int; _Compare = __gnu_cxx::__ops::_Val_less_iter]’
/usr/include/c++/13/bits/stl_algo.h:2070:32:   required from ‘_FIter std::upper_bound(_FIter, _FIter, const _Tp&) [with _FIter = __gnu_cxx::__normal_iterator<pair<long long int, pair<long long int, long long int> >*, vector<pair<long long int, pair<long long int, long long int> > > >; _Tp = long long int]’
answer.code:93:32:   required from here
/usr/include/c++/13/bits/predefined_ops.h:98:22: error: no match for ‘operator<’ (operand types are ‘const long long int’ and ‘std::pair<long long int, std::pair<long long int, long long int> >’)
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/13/bits/stl_algobase.h:67:
/usr/include/c++/13/bits/stl_iterator.h:1250:5: note: candidate: ‘template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)’
 1250 |     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:1250:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:98:22: note:   mismatched types ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’ and ‘const long long int’
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:1258:5: note: candidate: ‘template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)’
 1258 |     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:1258:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:98:22: note:   mismatched types ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’ and ‘const long long int’
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/13/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:181:
/usr/include/c++/13/bits/regex.h:1143:5: note: candidate: ‘template<class _BiIter> bool std::__cxx11::operator<(const sub_match<_BiIter>&, const sub_match<_BiIter>&)’
 1143 |     operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1143:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:98:22: note:   mismatched types ‘const std::__cxx11::sub_match<_BiIter>’ and ‘const long long int’
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/13/bits/regex.h:1224:5: note: candidate: ‘template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator<(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)’
 1224 |     operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1224:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:98:22: note:   mismatched types ‘std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>’ and ‘const long long int’
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/13/bits/regex.h:1317:5: note: candidate: ‘template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator<(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)’
 1317 |     operator<(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1317:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/predefined_ops.h:98:22: note:   mismatched types ‘...