QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#165751#6401. Classic: N Real DNA PotsZXG_DZXXWA 1ms3652kbC++171.8kb2023-09-05 21:25:112023-09-05 21:25:12

Judging History

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

  • [2023-09-05 21:25:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3652kb
  • [2023-09-05 21:25:11]
  • 提交

answer

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

#define x first
#define y second
typedef pair<int, int> PII;
typedef long long ll;

struct Fenwick
{
    int n;
    vector<ll> tr;
    Fenwick(int _n) : n(_n)
    {
        tr.resize(n + 1);
    }
    void add(int x, ll v)
    {
        for(int i = x; i <= n; i += i & -i) tr[i] = max(tr[i], v);
    }
    ll query(int x)
    {
        ll res = 0;
        for(int i = x; i >= 1; i -= i & -i) res = max(res, tr[i]);
        return res;
    }
};

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
    auto check = [&](double k)
    {
        vector<int> dp(n);
        vector<double> w(n);
        for(int i = 0; i < n; i++) w[i] = y[i] - k * x[i];
        vector<double> all;
        for(int i = 0; i < n; i++) all.push_back(w[i]);
        sort(all.begin(), all.end());
        all.erase(unique(all.begin(), all.end()), all.end());
        auto find = [&](double x)
        {
            return lower_bound(all.begin(), all.end(), x) - all.begin() + 1;
        };
        Fenwick tr(all.size() + 5);
        dp[0] = 1;
        tr.add(find(w[0]), 1);
        for(int i = 1; i < n; i++) 
        {
            dp[i] = 1;
            dp[i] = max((ll)dp[i], tr.query(find(w[i])) + 1);
            tr.add(find(w[i]), dp[i]);
        }
        return *max_element(dp.begin(), dp.end()) >= m;
    };    
    double l = -2e9, r = 2e9;
    int times = 50;
    while(times--)
    {
        double mid = (l + r) / 2;
        if(check(mid)) l = mid;
        else r = mid;
    }
    cout << fixed << setprecision(15) << l << '\n';
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    // int T; cin >> T; while(T--)
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3
1 2
2 4
3 3
4 1

output:

-1.000000082740371

result:

ok found '-1.0000001', expected '-1.0000000', error '0.0000001'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3652kb

input:

2 2
1 1
5 3

output:

0.499998265013346

result:

wrong answer 1st numbers differ - expected: '0.5000000', found: '0.4999983', error = '0.0000017'