답안 #428855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
428855 2021-06-15T14:56:19 Z tqbfjotld Sparklers (JOI17_sparklers) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define int __int128

pair<int,int> memo[1005][1005];
int arr[100005];

int K,T,N;
int M;

pair<int,int> func(int a, int b){
    if (a==b) return a==K?make_pair(arr[K]-M*T,arr[K]+M*T):make_pair(999999999999999999LL,-999999999999999999LL);
    if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
   // printf("%lld %lld, %lld\n",a,b,K);
    if (b<K || a>K) return {999999999999999999LL,-999999999999999999LL};
    auto opt1 = func(a,b-1);
    auto opt2 = func(a+1,b);
       // printf("opt1 = %lld %lld, \n",opt1);
       // printf("optw = %lld %lld, ab = %lld %lld\n",opt2,a,b);
    if (opt1.second<opt1.first){
        if (opt2.second<opt2.first) return memo[a][b] = {999999999999999999LL,-999999999999999999LL};
        int sz = (b-a);
        if (sz*T*M+arr[a]<opt2.first) return memo[a][b] = {999999999999999999LL,-999999999999999999LL};
        return memo[a][b] = {opt2.first-T*M,(sz+1)*T*M+arr[a]};
    }
    else {
            int sz = (b-a);
            if (-sz*T*M+arr[b]>opt1.second) return memo[a][b] = {999999999999999999LL,-999999999999999999LL};
            return memo[a][b] = {-(sz+1)*T*M+arr[b],opt1.second+T*M};

    }
}

bool test(int val){
    M = val;
    memset(memo,-1,sizeof(memo));
    auto res = func(0,N-1);
    //printf("val = %lld, res = %lld %lld\n",val,res);
    return res.second>res.first;
}

main(){
    long long n,k,t;
    scanf("%lld%lld%lld",&n,&k,&t);
    N = n; K = k; T = t;
    K--;
    for (int x = 0; x<N; x++){
        long long t;
        scanf("%lld",&t);
        arr[x] = t;
    }
    long long r = 1000000000LL/T+1;
    int l = -1LL;
    while (l+1<r){
        int mid = (l+r)/2;
        if (test(mid)){
            r = mid;
        }
        else l = mid;
    }
    printf("%lld\n",r);
}

Compilation message

sparklers.cpp: In function 'std::pair<__int128, __int128> func(__int128, __int128)':
sparklers.cpp:12:26: error: operands to '?:' have different types 'std::pair<__int128, __int128>' and 'std::pair<long long int, long long int>'
   12 |     if (a==b) return a==K?make_pair(arr[K]-M*T,arr[K]+M*T):make_pair(999999999999999999LL,-999999999999999999LL);
      |                      ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:12:26: note:   and each type can be converted to the other
sparklers.cpp:13:19: error: no match for 'operator!=' (operand types are 'std::pair<__int128, __int128>' and 'std::pair<long long int, long long int>')
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
      |                  |           |
      |                  |           pair<long long int,long long int>
      |                  pair<__int128,__int128>
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from sparklers.cpp:1:
/usr/include/c++/10/bits/regex.h:1064:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator!=(const std::__cxx11::sub_match<_BiIter>&, const std::__cxx11::sub_match<_BiIter>&)'
 1064 |     operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/10/bits/regex.h:1064:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from sparklers.cpp:1:
/usr/include/c++/10/bits/regex.h:1144:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const std::__cxx11::sub_match<_BiIter>&)'
 1144 |     operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/regex.h:1144:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from sparklers.cpp:1:
/usr/include/c++/10/bits/regex.h:1237:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(const std::__cxx11::sub_match<_BiIter>&, std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1237 |     operator!=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/regex.h:1237:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from sparklers.cpp:1:
/usr/include/c++/10/bits/regex.h:1311:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type*, const std::__cxx11::sub_match<_BiIter>&)'
 1311 |     operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/regex.h:1311:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<long long int, long long int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from sparklers.cpp:1:
/usr/include/c++/10/bits/regex.h:1405:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const std::__cxx11::sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)'
 1405 |     operator!=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/regex.h:1405:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from sparklers.cpp:1:
/usr/include/c++/10/bits/regex.h:1479:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type&, const std::__cxx11::sub_match<_BiIter>&)'
 1479 |     operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/regex.h:1479:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<long long int, long long int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from sparklers.cpp:1:
/usr/include/c++/10/bits/regex.h:1579:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const std::__cxx11::sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)'
 1579 |     operator!=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/regex.h:1579:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from sparklers.cpp:1:
/usr/include/c++/10/bits/regex.h:2126:5: note: candidate: 'template<class _Bi_iter, class _Alloc> bool std::__cxx11::operator!=(const std::__cxx11::match_results<_BiIter, _Alloc>&, const std::__cxx11::match_results<_BiIter, _Alloc>&)'
 2126 |     operator!=(const match_results<_Bi_iter, _Alloc>& __m1,
      |     ^~~~~~~~
/usr/include/c++/10/bits/regex.h:2126:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::__cxx11::match_results<_BiIter, _Alloc>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/iosfwd:40,
                 from /usr/include/c++/10/ios:38,
                 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 sparklers.cpp:1:
/usr/include/c++/10/bits/postypes.h:227:5: note: candidate: 'template<class _StateT> bool std::operator!=(const std::fpos<_StateT>&, const std::fpos<_StateT>&)'
  227 |     operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/10/bits/postypes.h:227:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::fpos<_StateT>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 sparklers.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:496:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
  496 |     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:496:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   deduced conflicting types for parameter '_T1' ('__int128' and 'long long int')
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 sparklers.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:372:5: note: candidate: 'template<class _Iterator> bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)'
  372 |     operator!=(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:372:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::reverse_iterator<_Iterator>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 sparklers.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:410:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)'
  410 |     operator!=(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:410:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::reverse_iterator<_Iterator>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 sparklers.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1444:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator!=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)'
 1444 |     operator!=(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1444:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::move_iterator<_IteratorL>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 sparklers.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1501:5: note: candidate: 'template<class _Iterator> bool std::operator!=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)'
 1501 |     operator!=(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1501:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::move_iterator<_IteratorL>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
In file included from /usr/include/c++/10/string:41,
                 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 sparklers.cpp:1:
/usr/include/c++/10/bits/allocator.h:213:5: note: candidate: 'template<class _T1, class _T2> bool std::operator!=(const std::allocator<_CharT>&, const std::allocator<_T2>&)'
  213 |     operator!=(const allocator<_T1>&, const allocator<_T2>&)
      |     ^~~~~~~~
/usr/include/c++/10/bits/allocator.h:213:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::allocator<_CharT>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
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 sparklers.cpp:1:
/usr/include/c++/10/bits/basic_string.h:6229:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 6229 |     operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6229:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   'std::pair<__int128, __int128>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
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 sparklers.cpp:1:
/usr/include/c++/10/bits/basic_string.h:6242:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 6242 |     operator!=(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6242:5: note:   template argument deduction/substitution failed:
sparklers.cpp:13:40: note:   mismatched types 'const _CharT*' and 'std::pair<__int128, __int128>'
   13 |     if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
      |                                        ^
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 sparklers.cpp:1:
/usr/include/c++/10/bits/basic_string.h:6254:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)'
 6254 |     operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6254:5: note:   template argument deduction/substitution