QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#174529 | #6632. Minimize Median | PERAPRO | WA | 3ms | 7712kb | C++20 | 3.1kb | 2023-09-10 08:53:13 | 2023-09-10 08:53:13 |
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 += -visit2[k.second];
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 ;
}
}
/*
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 7712kb
input:
3 3 5 0 2 5 2 3 2 4 6 13 3 5 3 2 5 3 3 2 4 6 13 3 5 6 2 5 2 3 2 4 6 13
output:
2147483647 2147483647 2147483647
result:
wrong answer 1st numbers differ - expected: '2', found: '2147483647'