QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#174535 | #6632. Minimize Median | PERAPRO | Compile Error | / | / | C++20 | 3.1kb | 2023-09-10 08:57:25 | 2023-09-10 08:57:25 |
Judging History
answer
/// Write by Daniel Perez .PERAPRO
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(), s.end()
#define mp make_pair
//#define int long long
#define ll long long
// typedef unsigned long long ull;
typedef long double ld;
using vi=vector<int>;
using vl=vector<ll>;
using pii=pair<int,int>;
#define endl '\n'
char el = '\n';
char esp = ' ';
int cost [1000001] ;
int cont [1000001] ;
// bool visit1 [1000001] ;
bitset<1000001> visit1;
long long visit2 [1000001 ] ;
int n , m , c ;
bool bus ( int h ){
long long sum1 = 0 ;
for ( int i = 0 ; i <= m ; i++ ){
visit1 [i] = 0 ;
visit2 [i] = -INT_MAX ;
}
long long cont1 = 0 ;
priority_queue < pair < int , int > > q ;
for ( int i = 0 ; i <= h ; i++ ){
q.push ( { 0 , i } ) ;
}
while ( !q.empty( ) ){
pair < int , int > k = q.top ( ) ;
q.pop ( ) ;
if ( visit1 [k.second] ) continue ;
visit1 [k.second] = true ;
for ( int i = 0 ; i < cont[k.second] ; i++ ){
sum1 += -max(visit2[k.second], k.first);
cont1++ ;
if ( sum1 > c ) return false;
if ( cont1 == n / 2 + 1 ) return true ;
}
for ( int i = 1 ; i <= m ; i++ ){
long long p = k.second * i ;
long long sum = - ( (- ( visit2[k.second])) + cost[i] ) ;
if ( p > m ) break ;
for ( int d = 0 ; d < i ; d++ ){
if ( p + d > m ) break ;
if ( sum < visit2[p+d] ) continue ;
if ( visit2[p+d] == -INT_MAX) q.push ( {sum , p + d }) ;
visit2[p+d] = sum ;
}
}
}
return false ;
}
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &v){
for(auto const &i: v){
os<<i<<" ";
}
os<<'\n';
return os;
}
string yes="YES";
string no="NO";
int32_t main(){
fast_io;
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
int tc;
cin>>tc;
while(tc--){
cin>>n>>m>>c ;
for ( int i = 0 ; i <= m ; i++ ) cont [i] = 0 ;
for ( int i = 0 ; i < n ; i++ ){
int a ;
cin>>a ;
cont[a]++ ;
}
for ( int i = 1 ;i <= m ;i++){
int a ;
cin>>a ;
cost[i] = a ;
}
int lo = 0 ;
int hi = m+1 ;
int best = INT_MAX ;
while ( lo < hi ){
int mid = ( lo + hi ) / 2 ;
if ( bus ( mid ) ){
best = min ( best , mid ) ;
hi = mid ;
}
else{
lo = mid + 1 ;
}
}
cout<<best<<endl ;
}
}
/*
*/
详细
answer.code: In function ‘bool bus(int)’: answer.code:46:25: error: no matching function for call to ‘max(long long int&, int&)’ 46 | sum1 += -max(visit2[k.second], k.first); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/11/bits/specfun.h:45, from /usr/include/c++/11/cmath:1935, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41, from answer.code:2: /usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’ 254 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/11/bits/stl_algobase.h:254:5: note: template argument deduction/substitution failed: answer.code:46:25: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’) 46 | sum1 += -max(visit2[k.second], k.first); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/11/bits/specfun.h:45, from /usr/include/c++/11/cmath:1935, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41, from answer.code:2: /usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’ 300 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/11/bits/stl_algobase.h:300:5: note: template argument deduction/substitution failed: answer.code:46:25: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’) 46 | sum1 += -max(visit2[k.second], k.first); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/11/string:52, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:2: /usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)’ 3461 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/11/bits/stl_algo.h:3461:5: note: template argument deduction/substitution failed: answer.code:46:25: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 46 | sum1 += -max(visit2[k.second], k.first); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/11/string:52, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:2: /usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)’ 3467 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/11/bits/stl_algo.h:3467:5: note: template argument deduction/substitution failed: answer.code:46:25: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 46 | sum1 += -max(visit2[k.second], k.first); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~