QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#105105#5505. Great ChasekingstonduyWA 869ms3632kbC++141.9kb2023-05-12 23:07:502023-05-12 23:07:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-12 23:07:52]
  • 评测
  • 测评结果:WA
  • 用时:869ms
  • 内存:3632kb
  • [2023-05-12 23:07:50]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define all(x) begin(x), end(x)
#define int long long
#define sz(x) (int)(x).size()

typedef pair<int, int> pii;
typedef vector<int> vi;


const int inf = (int)1e18;

long double updatePos(long double t, vector<pair<int, long double>>& cops, int flag) {
    long double pos = DBL_MAX;
    for (auto& i : cops) {
        if (pos > (i.second + i.first * t) * flag) {
            pos = (i.second + i.first * t) * flag;
        }
    }

    return pos;
}


long double BinSearch(long double l, long double r, vector<pair<int, long double >>& pos, vector<pair<int, long double >>& neg) {
    long double mid;
    int cnt= 100;

    while (cnt-- && r - l > 1e-12 ) {
        mid = (l + r) / 2.0;
        long double posL = -1 * updatePos(mid, neg, -1);
        long double posR = updatePos(mid, pos, 1);
        if (posR - posL < 0) {
            r = mid ;
        } else {
            l = mid;
        }
    }
    return mid;
}



signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin.exceptions(std::istream::failbit);
    // freopen("../input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);


    int t;
    cin >> t;
    while (t--) {
        int n, v;
        cin >> n >> v;
        vector<pair<int, long double >> pos;
        vector<pair<int, long double >> neg;
        long double p;
        int vel;
        long double dis = 0;
        for (int i = 0; i < n; i++) {

            cin >> p >> vel;
            dis = max(dis, abs(p));
            if (p > 0) {
                pos.push_back({ -vel, p });
            } else {
                neg.push_back({ vel, p });
            }
        }

        p = 0;

        long double t = BinSearch(0, dis, pos, neg);


        cout << fixed << setprecision(10) << t * v << '\n';

    }


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3632kb

input:

3
4 9
10 2
-7 2
-6 1
7 1
2 8
-1 7
1 6
2 3
-1000000000000 1
1000000000000 1

output:

38.2500000000
1.2307692308
3000000000000.0000000000

result:

ok 3 numbers

Test #2:

score: -100
Wrong Answer
time: 869ms
memory: 3620kb

input:

10000
200 997007
405524182320 754760
686939601648 419804
687047488212 715566
1446157132 4594
-670522037 4673
763634629282 253755
424307411732 275041
1582708381 8473
-667425982 4622
-522841486 1427
702430907988 460271
1405423646 1060
1497754648 6227
883363410675 723547
56899800372 46435
-810216390 64...

output:

145405766328.3491097540
16414958969.7272811523
5202715639.8351836884
321977234.1563257050
45384199210.2216845378
183885744.7692307706
1708925225.2304730145
89786664971.5579426959
13924365606.2873888453
412975327.5555555473
965508404.5121019587
4703493416.2883765553
352961619.3810443069
5575125771.79...

result:

wrong answer 4566th numbers differ - expected: '1.0000010', found: '1.0000012', error = '0.0000002'