QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#493544#8524. Weather ForecastNoPractice#WA 1ms5968kbC++142.1kb2024-07-27 10:18:172024-07-27 10:18:18

Judging History

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

  • [2024-07-27 10:18:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5968kb
  • [2024-07-27 10:18:17]
  • 提交

answer

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

#define ff first
#define ss second
#define bl ' '
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define comp(v) (v).erase(unique(all(v)), (v).end())

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
typedef pair<ll, ll> pll;

const int MAXN = 300300;
const int MOD = 998244353;
const int INF = 1e9;

ll arr[MAXN], dp[MAXN];
vector<ll> v, tree;
int n, k;

void update(int node, int s, int e, int idx, ll val) {
    if(e < idx || idx < s) return;
    if(s == e) {
        tree[node] = max(tree[node], val);
        return;
    }

    int mid = s+e>>1;
    update(node<<1, s, mid, idx, val); update(node<<1|1, mid+1, e, idx, val);
    tree[node] = max(tree[node<<1], tree[node<<1|1]);
}

ll solve(int node, int s, int e, int l, int r) {
    if(e < l || r < s) return LLONG_MIN;
    if(l <= s && e <=r) return tree[node];

    int mid = s+e>>1;
    return max(solve(node<<1, s, mid, l, r), solve(node<<1|1, mid+1, e, l, r));
}

bool chk(int mid) {
    if(arr[n]*100000 < n*mid) return false;

    v.clear();
    for(int i = 0; i <= n; i++) {
        v.push_back(100000*arr[i]-i*mid);
    }

    sort(all(v)); comp(v);

    int sz = v.size();
    tree.clear(); tree.resize(4*sz, LLONG_MIN);

    dp[0] = 0;
    int x = lower_bound(all(v), 100000*arr[0]-0*mid)-v.begin();
    update(1, 0, sz-1, x, dp[0]);
    for(int i = 1; i <= n; i++) {
        x = lower_bound(all(v), 100000*arr[i]-i*mid)-v.begin();

        dp[i] = LLONG_MIN;
        ll t = solve(1, 0, sz-1, 0, x);//cout<<t<<bl;
        if(t != LLONG_MIN) dp[i] = t+1;

        update(1, 0, sz-1, x, dp[i]);//cout<<dp[i]<<endl;
    }

    return dp[n] >= k;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> arr[i];
        arr[i] += arr[i-1];
    }//return chk(1);

    int lb = 0, ub = 1000*100000, mid;
    while(lb < ub) {
        mid = lb+ub+1>>1;
        if(chk(mid)) lb = mid;
        else ub = mid-1;
    }

    cout << (double)lb/100000;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5968kb

input:

7 3
1 3 1 2 2 2 1

output:

1.66666

result:

ok found '1.66666', expected '1.66667', error '0.00001'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5968kb

input:

1 1
1

output:

1

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5872kb

input:

2 1
2 1

output:

1.5

result:

ok found '1.50000', expected '1.50000', error '0.00000'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5948kb

input:

3 2
2 4 4

output:

3

result:

ok found '3.00000', expected '3.00000', error '0.00000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 5872kb

input:

4 2
6 7 3 12

output:

6.5

result:

ok found '6.50000', expected '6.50000', error '0.00000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 5948kb

input:

5 3
17 23 13 12 21

output:

16.5

result:

ok found '16.50000', expected '16.50000', error '0.00000'

Test #7:

score: 0
Accepted
time: 1ms
memory: 5860kb

input:

7 4
3 37 46 23 46 6 31

output:

23

result:

ok found '23.00000', expected '23.00000', error '0.00000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 5856kb

input:

10 5
30 91 36 53 74 91 37 1 76 3

output:

39.5

result:

ok found '39.50000', expected '39.50000', error '0.00000'

Test #9:

score: -100
Wrong Answer
time: 0ms
memory: 5928kb

input:

100 50
593 336 577 842 505 78 665 825 990 895 952 782 721 242 421 951 786 994 238 154 356 483 686 143 220 473 920 353 738 690 96 915 913 157 412 882 465 585 963 635 68 72 901 143 50 558 310 504 987 97 588 987 841 829 780 497 758 909 503 585 91 657 912 870 663 606 748 492 175 92 375 768 773 206 676 8...

output:

502

result:

wrong answer 1st numbers differ - expected: '483.00000', found: '502.00000', error = '19.00000'