QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#378522#6401. Classic: N Real DNA PotsplutosWA 2ms6064kbC++171.9kb2024-04-06 13:22:172024-04-06 13:22:18

Judging History

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

  • [2024-04-06 13:22:18]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6064kb
  • [2024-04-06 13:22:17]
  • 提交

answer

#include <bits/stdc++.h>

void Yes() {
    std::cout << "YES" << "\n";
    return;
}

void No() {
    std::cout << "NO" << "\n";
    return;
}

template<typename T>
void out(T x) { std::cout << x << "\n"; }

using namespace std;
using ll = long long;
using PII = pair<double, int>;

const int N = 2e5 + 10;
int nxt[N], be[N];
double x[N], y[N];

void Solve() {
    ll n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> x[i] >> y[i], nxt[i] = i + 1, be[i] = i - 1;

    set<PII> st;
    for (int i = 2; i <= n; i++) {
        st.insert({(y[i] - y[i - 1]) / (x[i] - x[i - 1]), i - 1});
    }
    for (int i = m + 1; i <= n; i++) {
        auto now = *st.begin();
//        cout<<now.first<<"\n";
        st.erase(now);
        int id = now.second;

        int bid = be[id];
        int nid = nxt[id];
        int nnid = nxt[nid];

        if (nnid <= n && bid >= 1) {
//            cout<<1<<"\n";
            double shanho = (y[nnid] - y[id]) / (x[nnid] - x[id]);

            double shanqian = (y[nid] - y[bid]) / (x[nid] - x[bid]);

            if (shanho >= shanqian) {
                st.erase({(y[nnid] - y[nid]) / (x[nnid] - x[nid]), nid});
                st.insert({(y[nnid] - y[id]) / (x[nnid] - x[id]), id});
                nxt[id] = nnid;
                be[nnid] = id;
            } else {
                st.erase({(y[id] - y[bid]) / (x[id] - x[bid]), bid});
                st.insert({(y[nid] - y[bid]) / (x[nid] - x[bid]), bid});
                nxt[id] = nid;
                be[nid] = id;
            }
        } else if (nnid <= n) {
            be[nid] = bid;
        } else if (bid >= 1) {
            nxt[id] = nnid;
        }

    }
    cout << (*st.begin()).first << "\n";
}

signed main() {
    cout << fixed << setprecision(10);
    int t = 1;
//    cin>>t;
    while (t--)
        Solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3
1 2
2 4
3 3
4 1

output:

-1.0000000000

result:

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

Test #2:

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

input:

2 2
1 1
5 3

output:

0.5000000000

result:

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

Test #3:

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

input:

2 2
222640995 547139825
489207317 725361095

output:

0.6685813446

result:

ok found '0.6685813', expected '0.6685813', error '0.0000000'

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 6024kb

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:

-4.6647785324

result:

wrong answer 1st numbers differ - expected: '3.7932105', found: '-4.6647785', error = '2.2297706'