QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#703140 | #6632. Minimize Median | gates_orz | WA | 624ms | 185704kb | C++20 | 2.6kb | 2024-11-02 17:15:05 | 2024-11-02 17:15:14 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
using LL=long long;
const int N=1e6+10;
const int M=N*2;
int n,m;
int k;
using PII=pair<int,int>;
vector<PII>p[1000005];
void init() {
for(int i=2;i<=1000000;i++)
{
for(int j=i;j<=1000000;j+=i)
{
p[j].push_back({i,j/i});
}
}
}
inline LL min(LL a,LL b) {
return a>b?b:a;
}
int a[N];
LL cost[N];
LL Real[N];
LL suf[N];
void solve() {
//vector<int>a(n+1);
/*vector<LL>cost(m+1);
vector<LL>Real(m+1,1e18);
vector<LL>suf(m+1);*/
cin>>n>>m>>k;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)cin>>cost[i];
for(int i=2;i<=m;i++)Real[i]=cost[i];
Real[1]=1e18;
Real[m+1]=1e18;
//cerr<<"???"<<"\n";
for(int i=2;i<=m;i++) {
for(auto [t1,t2]:p[i]) {
//cerr<<"t1="<<t1<<" t2="<<t2<<"\n";
Real[i]=min(Real[i],Real[t1]+Real[t2]);
}
}
for(int i=m;i>=1;i--) {
if(i==m)suf[i]=Real[i];
else {
suf[i]=min(suf[i+1],Real[i]);
}
}
for(int i=2;i<=m;i++) {
Real[m+1]=min(Real[m+1],Real[i]+suf[m+1-i]);
}
for(int i=m+1;i>=1;i--) {
if(i==m+1)suf[i]=Real[i];
else {
suf[i]=min(suf[i+1],Real[i]);
}
}
sort(a+1,a+1+n);
auto check=[&](int x) {
int cnt=0,p=0;
for(int i=1;i<=n;i++) {
if(a[i]<=x)cnt++;
else {
p=i;
break;
}
}
int num=n/2+1-cnt;
LL tot=0;
for(int i=p;i<=p+num-1;i++) {
int need;
if(x)need=(a[i]+x-1)/x;
else need=a[i]+1;
need=min(need,m+1);
tot+=suf[need];
if(tot>k)return false;
}
return true;
};
if(check(0)) {
cout<<"0\n";
return;
}
int l=0,r=a[n/2+1];
int res=0;
while(l<=r) {
int mid=(l+r)/2;
/*if(mid==2) {
cerr<<"mid="<<mid<<" check="<<check(mid)<<"\n";
}*/
if(check(mid))res=mid,r=mid-1;
else l=mid+1;
}
cout<<res<<"\n";
}
/*
1
3 5 0
2 5 2
3 2 4 6 13
1
3 5 3
2 5 3
3 2 4 6 13
1
3 5 6
2 5 2
3 2 4 6 13
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
*/
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T=1;
cin>>T;
init();
//find_prime(1000005);
while(T--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 595ms
memory: 185704kb
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:
2 2 1
result:
ok 3 number(s): "2 2 1"
Test #2:
score: -100
Wrong Answer
time: 624ms
memory: 185676kb
input:
100000 5 10 5 3 7 1 10 10 11 6 11 6 1 8 9 1 3 1 5 6 51 2 2 2 5 1 42 61 26 59 100 54 5 10 76 7 5 8 4 7 97 4 44 83 61 45 24 88 44 44 5 8 90 1 1 5 1 3 35 15 53 97 71 83 26 7 5 3 52 1 1 3 1 1 22 6 93 5 6 28 6 6 1 3 1 9 31 2 19 10 27 5 8 31 3 6 2 1 2 32 29 13 7 57 34 9 5 5 6 75 3 3 4 5 4 40 56 38 60 17 3...
output:
0 2 0 0 0 0 0 0 3 4 0 0 0 0 1 1 0 0 0 0 1 1 0 2 2 0 1 0 0 0 2 0 0 0 2 2 0 1 0 0 0 0 1 0 2 4 1 1 0 0 2 0 0 7 0 2 0 0 0 1 1 0 1 0 1 0 0 2 1 0 6 3 0 0 1 0 2 0 0 3 0 1 0 1 0 2 0 0 0 1 1 2 2 4 0 0 0 0 0 0 1 2 2 1 2 2 0 1 1 0 0 0 0 0 1 2 1 4 1 0 4 1 2 1 0 0 0 0 1 2 1 0 0 2 3 1 0 1 1 1 0 1 5 0 1 2 0 2 0 1 ...
result:
wrong answer 27th numbers differ - expected: '0', found: '1'