QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#763858 | #6609. Scholomance Academy | AmiyaCast# | WA | 0ms | 3864kb | C++20 | 1.7kb | 2024-11-19 22:26:40 | 2024-11-19 22:26:45 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define pii pair<ll, ll>
const ll inf = 2e18;
const double eps = 1e-9;
using namespace std;
void slv(){
ll n; cin >> n;
vector<pii> a(n + 1);
for(int i = 1; i <= n; ++i) {
ll x; string s;
cin >> s >> x;
a[i] = {s[0] == '+' ? 1 : -1, x};
}
ll sump = 0, sumn = 0, tp = 0, fp = 0;
for(int i = 1; i <= n; ++i) {
if(a[i].first == 1) {
sump ++;
} else {
sumn++;
}
}
sort(a.begin() + 1, a.end(), [&](pii x, pii y) {
return x.second < y.second;
});
vector<pii> ans;
ans.push_back({0, 0});
for(int i = 1, j; i <= n; ++i) {
for(j = i; j <= n && a[j].second == a[i].second; ++j);
--j;
for(int k = i; k <= j; ++k) {
if(a[k].first == 1) tp++;
if(a[k].first == -1) fp++;
}
ans.push_back({tp, fp});
i = j;
}
// cout << "ok" << endl;
ll Ans = 0;
ll maxn = 0.0, lst = 0.0;
sort(ans.begin(), ans.end(), [&](pii x, pii y){
if(x.second == y.second) return x.first > y.first;
return x.second < y.second;
});
for(auto [p, f]: ans) {
maxn = max(maxn, p);
Ans += maxn * (f - lst);
lst = f;
}
Ans += maxn * (sumn - lst);
cout << fixed << setprecision(14) << ((long double)sump * sumn - Ans + 0.0) / (sump * sumn) << endl;
}
int main(){
//ios::sync_with_stdio(0), cin.tie(0);
int _ = 1;
//cin >> _;
while(_--) slv();
return 0;
}
/*
6
+ 7
- 2
- 5
+ 4
- 2
+ 6
*/
/*
3
+ 2
- 3
- 1
*/
/*
8
+ 34
+ 33
+ 26
- 34
- 38
+ 39
- 7
- 27
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3864kb
input:
3 + 2 - 3 - 1
output:
0.00000000000000
result:
wrong answer 1st numbers differ - expected: '0.5000000', found: '0.0000000', error = '0.5000000'