QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#703485#6632. Minimize Mediangates_orzWA 651ms185796kbC++203.0kb2024-11-02 17:52:322024-11-02 17:52:38

Judging History

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

  • [2024-11-02 17:52:38]
  • 评测
  • 测评结果:WA
  • 用时:651ms
  • 内存:185796kb
  • [2024-11-02 17:52:32]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

using LL=long long;
//#define int LL
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+i)/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]);
        }
    }
    suf[1]=0;

    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;
            }
        }
        if(cnt>=n/2+1)return true;
        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;*/

        LL tot=0;
        for(int i=1;i<=n/2+1;i++) {
            if(a[i]<=x)continue;
            int need;
            if(x)need=(a[i]+x-1)/x;
            else need=a[i]+1;
            //need=min(need,m+1);
            tot+=suf[need];
        }
        return tot<=k;

        LL sum=0;
        for(int i=1;i<=n/2+1;i++) {
            sum+=suf[a[i]/(x+1)+1];
        }
        return sum<=k;
    };
    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(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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 606ms
memory: 185796kb

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: 651ms
memory: 185668kb

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
0
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
0
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
0
...

result:

wrong answer 56th numbers differ - expected: '1', found: '2'