QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#485201#6632. Minimize Medianucup-team1525#WA 481ms124148kbC++202.5kb2024-07-20 14:56:152024-07-20 14:56:15

Judging History

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

  • [2024-07-20 14:56:15]
  • 评测
  • 测评结果:WA
  • 用时:481ms
  • 内存:124148kb
  • [2024-07-20 14:56:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int SIZ = 30000000 + 40;
const ll INF = 1e18;
char buf1[SIZ];
char *p1 = buf1, *p2 = buf1;
inline char readchar() {
    if (p1 == p2)
        p1 = buf1, p2 = buf1 + fread(buf1, 1, SIZ, stdin);
    return p1 == p2 ? EOF : *p1++;
}
int read() {
    int ret, c;
    while ((c = readchar()) > '9' || c < '0')
        ;
    ret = c - '0';
    while ((c = readchar()) >= '0' && c <= '9')
        ret = ret * 10 + c - '0';
    return ret;
}

const int N = 1e6 + 60;

int n, m;
ll K;
int a[N];
ll cost[N];
vector<int> div2[N];
ll dp[N];

void init() {
    for (int i = 1; i <= 1000000; i++) {
        for (int j = i; j <= 1000000; j += i)
            div2[j].push_back(i);
    }
}

ll mn;

void prep() {
    for (int i = 1; i <= m; i++)
        dp[i] = cost[i];
    for (int i = 1; i <= m; i++)
        for (auto &d : div2[i]) {
            dp[i] = min(dp[i], dp[d] + dp[i / d]);
        }
    // for(int i = 1; i <= m; i++)
    //     cout << dp[i] << " ";
    // cout << "\n===\n";
    dp[m + 1] = INF;
    for (int i = m - 1; i >= 1; i--)
        dp[i] = min(dp[i], dp[i + 1]);
    mn = INF;
    for (int i = 1; i <= m; i++) {
        ll y = (m + 1 + i - 1) / i;
        // cout << i << " " << y << " | " << dp[i] + dp[y] <<"\n";
        mn = min(mn, dp[i] + dp[y]);
    }
    // cout << mn << endl;
    dp[m + 1] = mn;
    for (int i = m; i >= 1; i--)
        dp[i] = min(dp[i], dp[i + 1]);
}

bool check(int mid) {
    int cnt = 0;
    for (int i = 1; i <= n; i++)
        cnt += (a[i] <= mid);
    if (cnt * 2 >= n)
        return true;
    ll total = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] > mid) {
            int x = (mid == 0 ? a[i] + 1 : (a[i] + mid - 1) / mid);
            ll now = dp[x];
            if (now + total <= K)
                total += now, cnt++;
        }
        if (cnt * 2 >= n)
            return true;
    }
    return false;
}

void solve() {
    n = read(), m = read(), K = read();
    for (int i = 1; i <= n; i++)
        a[i] = read();
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= m; i++)
        cost[i] = read();
    prep();

    int l = 0, r = m, ans = m;
    while (l <= r) {
        int mid = l + (r - l) / 2;
        if (check(mid))
            r = mid - 1, ans = mid;
        else
            l = mid + 1;
    }
    cout << ans << '\n';
}

int main() {
    init();
    int T = read();
    while (T--)
        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 464ms
memory: 122088kb

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: 481ms
memory: 124148kb

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'