QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#543853#8524. Weather ForecastHTensorWA 1ms4060kbC++172.1kb2024-09-01 22:12:112024-09-01 22:12:11

Judging History

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

  • [2024-09-01 22:12:11]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4060kb
  • [2024-09-01 22:12:11]
  • 提交

answer

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

#define int long long
using db = long double;
class BIT {
public:
    vector<int> val;
    BIT() { }
    BIT(int n) { val.resize(n + 1); }
    void clear() {
        fill(val.begin(), val.end(), -1);
    }
    int lowbit(int x) { return x & -x; }
	void add(int u, int x) {
		for(int i = u; i < (int)val.size(); i += lowbit(i)) val[i] = max(x, val[i]);
	}

	int query(int u) { 
		int ans = -1; for(int i = u; i; i -= lowbit(i)) ans = max(ans, val[i]); return ans;
	}
};

// results start with 1
void discretize(vector<db>& a) {
    vector<db> b(a);
    sort(b.begin() + 1, b.end());
    b.erase(unique(b.begin() + 1, b.end()), b.end());
    for(int i = 1; i < (int)a.size(); i++) 
        a[i] = lower_bound(b.begin() + 1, b.end(), a[i]) - b.begin();
}

void solve() {
    int n, k;
    cin >> n >> k;

    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector<int> s(n + 1);
    for (int i = 1; i <= n; i++) {
        s[i] = s[i - 1] + a[i];
    }
    auto check = [&](db m) {
        vector<db> v(n + 1);
        for (int i = 1; i <= n; i++) {
            v[i] = s[i] - i * m;
            // cerr << v[i] << " \n"[i == n];
        }
        discretize(v);
        BIT bit(n);
        vector<int> dp(n + 1);
        for (int i = 1; i <= n; i++) {
            dp[i] = bit.query(v[i] - 1) + 1;
            // cerr << i << ": " << v[i] << " " << bit.query(v[i] - 1) << " " << dp[i] << "\n"; 
            bit.add(v[i], dp[i]);
        }
        // for (int i = 1; i <= n; i++) {
        //     cerr << dp[i] << " \n"[i == n];
        // }
        return dp[n] >= k;
    };
    
    // check(1.7);

    db lo = 0, hi = 1000;
    while (hi - lo > 1e-9) {
        db m = (lo + hi) / 2;
        if (check(m)) {
            lo = m;
        } else {
            hi = m;
        }
    }

    cout << fixed << setprecision(10) << (lo + hi) / 2 << "\n";
}
signed main() {
    ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int t = 1;
    while (t--) {
        solve();
    }

    return 0;
}

/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 3
1 3 1 2 2 2 1

output:

1.6666666666

result:

ok found '1.66667', expected '1.66667', error '0.00000'

Test #2:

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

input:

1 1
1

output:

0.0000000005

result:

wrong answer 1st numbers differ - expected: '1.00000', found: '0.00000', error = '1.00000'