QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#495951#6401. Classic: N Real DNA Potstien_noobWA 3ms3928kbC++141.6kb2024-07-28 00:46:492024-07-28 00:46:49

Judging History

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

  • [2024-07-28 00:46:49]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3928kb
  • [2024-07-28 00:46:49]
  • 提交

answer

//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 1e5;
pair<int, int> a[N + 1];
int n, k;
int id[N + 1], e[N + 1];
void read()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> a[i].first >> a[i].second;
        id[i] = i;
    }
}
bool check(long double mid)
{
    sort(id + 1, id + n + 1, [&] (const int &i, const int &j)
    {
        return (long double)(a[i].second) - mid * a[i].first > (long double)(a[j].second) - mid * a[j].first;
    });
    for (int i = 1; i <= n; ++ i)
    {
        e[i] = 1e9;
        int j = lower_bound(e + 1, e + i + 1, id[i]) - e;
        if (j >= k)
        {
            return true;
        }
        e[j] = id[i];
    }
    return false;
}
void solve()
{
    sort(a + 1, a + n + 1);
    long double low = -1e9, high = 1e9;
    for (int t = 1; t <= 64; ++ t)
    {
        long double mid = (low + high)/2;
        if (check(mid))
        {
            high = mid;
        }
        else 
        {
            low = mid;
        }
    }
    cout << fixed << setprecision(6) << low;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3832kb

input:

4 3
1 2
2 4
3 3
4 1

output:

-1.000000

result:

ok found '-1.0000000', expected '-1.0000000', error '-0.0000000'

Test #2:

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

input:

2 2
1 1
5 3

output:

0.500000

result:

ok found '0.5000000', expected '0.5000000', error '0.0000000'

Test #3:

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

input:

2 2
222640995 547139825
489207317 725361095

output:

0.668581

result:

ok found '0.6685810', expected '0.6685813', error '0.0000003'

Test #4:

score: -100
Wrong Answer
time: 3ms
memory: 3928kb

input:

1000 20
545612 774435015
828317 212155588
5294705 85926095
5648835 764528941
6159263 570820268
7177330 744079287
8446124 162286636
8735551 586528841
9263030 524140841
9505706 636254627
12111352 182639083
12750780 238494418
13149143 913232250
13382784 11485121
13699797 414697815
14263990 423817548
15...

output:

-3.405304

result:

wrong answer 1st numbers differ - expected: '3.7932105', found: '-3.4053040', error = '1.8977366'