QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#780869#8676. Three Kinds of Diceucup-team5217#WA 164ms50540kbC++233.6kb2024-11-25 13:42:112024-11-25 13:42:17

Judging History

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

  • [2024-11-25 13:42:17]
  • 评测
  • 测评结果:WA
  • 用时:164ms
  • 内存:50540kb
  • [2024-11-25 13:42:11]
  • 提交

answer

#include <bits/stdc++.h>
#define ldb long double

using namespace std;

const int N = 1e6 + 10;
int n, m;
int a[N], b[N];
int tot;
ldb cntx[N], cnty[N];
int lsh[N];
// int x[N], y[N];
struct vec{
    ldb x,y;
    vec(ldb a=0,ldb b=0){x=a,y=b;}
    vec operator+(const vec a)const {
        return {x+a.x,y+a.y};
    }
    vec operator-(const vec a)const {
        return {x-a.x,y-a.y};
    }
    vec operator*(ldb a)const {
        return {x*a,y*a};
    }
    ldb operator*(const vec a)const {
        return x*a.x+y*a.y;
    }    
    ldb operator^(const vec a)const {
        return x*a.y-y*a.x;
    }  
    ldb len(){
        return sqrt(x*x+y*y);
    }
    ldb len2(){
        return (x*x+y*y);
    }
};

vec p[N];
ldb ans;

bool cmp(vec a, vec b) {
    return a.x < b.x;
}

ldb solve1() {
    for (int i = 1; i <= tot; ++i) {
        p[i].x = cntx[i];
        p[i].y = cnty[i];
        // cerr << p[i].x << ' ' << p[i].y << ' ' << lsh[i] << '\n';
    }
    sort(p + 1, p + tot + 1, cmp);
    vector<vec> q;
    for (int i = 1; i <= tot; ++i) {
        while (q.size() >= 2 && (((p[i] - q[q.size() - 2]) ^ (q[q.size() - 1] - q[q.size() - 2])) >= 0)) q.pop_back();
        q.push_back(p[i]);
    }
    // for (int i = 0; i < q.size(); ++i) {
    //     cerr << q[i].x << ' ' << q[i].y << '\n';
    // }
    for (int i = 0; i + 1 < q.size(); ++i) {
        if (q[i].x <= 0 && q[i + 1].x >= 0) {
            return q[i].y + (q[i + 1].y - q[i].y) * ((-q[i].x) / (q[i + 1].x - q[i].x));
        }
    }
    return 0;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    scanf("%d", &m);
    for (int i = 1; i <= m; ++i) {
        scanf("%d", &b[i]);
    }
    sort(a + 1, a + n + 1);
    sort(b + 1, b + m + 1);
    long long cnt = 0;
    for (int i = 1; i <= m; ++i) {
        cnt += lower_bound(a + 1, a + n + 1, b[i]) - a - 1;
        cnt -= (n - (upper_bound(a + 1, a + n + 1, b[i]) - a) + 1);
    }
    if (cnt > 0) {
        swap(n, m);
        swap(a, b);
    }
    auto ope=[&](){
        // cerr << n << ' ' << m << '\n';
        tot = 0;    
        for (int i = 1; i <= n; ++i) {
            lsh[++tot] = max(1, a[i] - 1);
            lsh[++tot] = a[i];
            lsh[++tot] = min(1000000001, a[i] + 1);
        }
        for (int i = 1; i <= m; ++i) {
            lsh[++tot] = max(1, b[i] - 1);
            lsh[++tot] = b[i];
            lsh[++tot] = min(1000000001, a[i] + 1);
        }
        sort(lsh + 1, lsh + tot + 1);
        tot = unique(lsh + 1, lsh + tot + 1) - lsh - 1;
        for (int i = 1; i <= tot; ++i) {
            cntx[i] += lower_bound(a + 1, a + n + 1, lsh[i]) - a - 1;
            cntx[i] -= (n - (upper_bound(a + 1, a + n + 1, lsh[i]) - a) + 1);
        }
        for (int i = 1; i <= tot; ++i) {
            cnty[i] += lower_bound(b + 1, b + m + 1, lsh[i]) - b - 1;
            cnty[i] += 1.0 * (upper_bound(b + 1, b + m + 1, lsh[i]) - lower_bound(b + 1, b + m + 1, lsh[i])) / 2;
            cnty[i] /= m;
        }
        ans = solve1();
        for (int i = 1; i <= tot; ++i) cntx[i] = cnty[i] = 0;
    };
    ope();
    printf("%.9Lf ", ans);
    // return 0;
    swap(n, m);
    swap(a, b);

    for (int i = 1; i <= n; ++i) a[i] = 1000000002 - a[i];
    for (int i = 1; i <= m; ++i) b[i] = 1000000002 - b[i];
    sort(a + 1, a + n + 1);
    sort(b + 1, b + m + 1);
    // sort()
    ope();
    printf("%.9Lf\n", 1 - ans);

    return 0;
}

/*
6 1 1 6 6 8 8
3 2 4 9
*/
/*
*/
/*
4 9 3 7 5
 3 4 2 3
*/
/*
3 3 3 3
1 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 45260kb

input:

3 2 4 9
3 1 6 8

output:

0.291666667 0.750000000

result:

ok 2 numbers

Test #2:

score: 0
Accepted
time: 3ms
memory: 43160kb

input:

3 1 6 8
6 2 2 4 4 9 9

output:

0.291666667 0.750000000

result:

ok 2 numbers

Test #3:

score: 0
Accepted
time: 9ms
memory: 43220kb

input:

1 1
1 2

output:

0.750000000 0.000000000

result:

ok 2 numbers

Test #4:

score: 0
Accepted
time: 9ms
memory: 45248kb

input:

5 2 2 2 3 3
6 5 5 6 6 6 7

output:

0.500000000 0.500000000

result:

ok 2 numbers

Test #5:

score: 0
Accepted
time: 11ms
memory: 45412kb

input:

6 2 2 7 7 9 9
6 3 3 5 5 10 10

output:

0.250000000 0.750000000

result:

ok 2 numbers

Test #6:

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

input:

11 12 11 15 9 3 8 18 4 17 13 9
11 8 18 5 15 12 5 11 11 11 3 8

output:

0.473684211 0.525000000

result:

ok 2 numbers

Test #7:

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

input:

20 17 18 29 37 5 15 5 9 37 34 12 38 26 29 2 40 23 20 4 12
23 22 2 24 33 6 19 15 31 1 18 30 11 40 13 2 19 5 39 37 22 9 31 26

output:

0.440503432 0.554166667

result:

ok 2 numbers

Test #8:

score: 0
Accepted
time: 13ms
memory: 45352kb

input:

40 52 22 29 52 44 3 69 45 40 73 66 51 2 21 20 51 49 34 72 64 69 68 56 4 6 39 29 18 43 6 56 15 22 31 25 78 59 58 40 66
46 52 24 40 12 56 7 4 29 12 26 45 39 27 47 55 45 17 74 28 12 75 77 77 73 41 21 20 23 55 13 58 21 43 11 22 2 67 18 49 56 15 26 25 35 20 61

output:

0.433971447 0.565224359

result:

ok 2 numbers

Test #9:

score: 0
Accepted
time: 7ms
memory: 45500kb

input:

76 54 80 5 41 10 124 87 45 67 42 118 33 128 118 21 40 41 3 18 69 131 113 121 106 99 72 108 85 101 108 72 27 13 45 133 137 4 62 30 111 71 39 31 120 79 91 30 58 43 6 60 65 83 83 42 83 26 108 20 133 24 8 125 138 100 21 103 81 45 102 76 44 118 109 18 67
81 4 15 26 65 110 48 126 39 128 82 1 43 134 18 69 ...

output:

0.421188630 0.573711063

result:

ok 2 numbers

Test #10:

score: 0
Accepted
time: 7ms
memory: 45252kb

input:

96 11 1 23 7 6 41 8 11 40 5 24 32 40 40 24 24 24 23 17 21 27 21 21 42 1 29 15 45 24 44 50 1 34 11 7 1 12 45 15 3 14 9 25 5 5 20 31 1 41 44 7 27 28 11 24 37 50 7 7 48 1 22 4 5 40 32 33 32 18 18 26 49 28 34 42 29 15 18 4 42 12 21 17 10 47 2 44 40 8 15 7 44 25 5 13 19
88 16 30 20 24 2 26 39 28 1 16 10 ...

output:

0.481854839 0.518595041

result:

ok 2 numbers

Test #11:

score: 0
Accepted
time: 7ms
memory: 45264kb

input:

208 31 110 162 24 386 12 262 283 384 392 361 168 58 129 155 45 36 70 2 127 296 380 188 125 148 77 117 272 219 38 79 322 70 91 115 273 228 375 398 353 277 307 258 60 42 60 298 109 60 158 192 159 29 165 103 51 304 313 392 113 62 149 203 152 3 373 206 144 136 214 151 348 287 181 202 367 67 138 388 93 3...

output:

0.495587799 0.504427083

result:

ok 2 numbers

Test #12:

score: 0
Accepted
time: 6ms
memory: 45380kb

input:

1170 1311 1924 962 906 1767 1811 1941 1956 1311 364 371 1825 1155 918 1625 1882 1082 198 889 924 1830 244 589 1639 296 1326 1663 379 1479 1369 729 1698 870 1845 217 888 754 858 966 1887 61 1801 1002 1185 1848 610 1914 1742 409 648 781 445 1217 96 1639 1681 1028 923 123 1234 909 569 747 1182 1538 368...

output:

0.485542699 0.514105003

result:

ok 2 numbers

Test #13:

score: 0
Accepted
time: 37ms
memory: 46552kb

input:

22713 21796 19194 13993 27763 16658 14855 3720 21919 4029 27311 21879 4981 25538 24982 5230 7339 4299 26976 30753 39183 38686 25483 3489 12855 28134 34477 25105 39953 31801 23937 31229 26076 32962 33965 6078 33306 15915 21622 3643 29726 2542 27764 4554 17811 17329 10576 26448 24416 30696 3230 3730 1...

output:

0.499529338 0.500470603

result:

ok 2 numbers

Test #14:

score: 0
Accepted
time: 19ms
memory: 45316kb

input:

100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

0.750000000 0.000000000

result:

ok 2 numbers

Test #15:

score: 0
Accepted
time: 23ms
memory: 45316kb

input:

1 1
100000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100...

output:

0.750000000 0.000000000

result:

ok 2 numbers

Test #16:

score: 0
Accepted
time: 45ms
memory: 47244kb

input:

100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

0.750000000 0.000000000

result:

ok 2 numbers

Test #17:

score: 0
Accepted
time: 30ms
memory: 47556kb

input:

100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

0.500005000 0.499995000

result:

ok 2 numbers

Test #18:

score: 0
Accepted
time: 34ms
memory: 47560kb

input:

100000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 10000...

output:

0.500000000 0.500000000

result:

ok 2 numbers

Test #19:

score: 0
Accepted
time: 164ms
memory: 50436kb

input:

100000 100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 9995...

output:

0.500000000 0.500000000

result:

ok 2 numbers

Test #20:

score: 0
Accepted
time: 158ms
memory: 50540kb

input:

100000 100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 9995...

output:

0.500000000 0.500000000

result:

ok 2 numbers

Test #21:

score: 0
Accepted
time: 38ms
memory: 45464kb

input:

99818 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

0.212675039 0.787320895

result:

ok 2 numbers

Test #22:

score: -100
Wrong Answer
time: 44ms
memory: 47660kb

input:

99536 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

0.009384890 0.746582508

result:

wrong answer 2nd numbers differ - expected: '0.7476316', found: '0.7465825', error = '0.0010490'