QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#763882 | #6609. Scholomance Academy | AmiyaCast# | WA | 1ms | 3956kb | C++20 | 1.7kb | 2024-11-19 22:34:36 | 2024-11-19 22:34:38 |
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;
});
tp = sump, fp = sumn;
vector<pii> ans;
ans.push_back({tp, fp});
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;
}
ll Ans = 0, maxn = 0, lst = 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(int i = 0, j; i < ans.size(); ++i) {
maxn = max(maxn, ans[i].first);
Ans += maxn * (ans[i].second - lst);
lst = ans[i].second;
}
cout << fixed << setprecision(14) << (long double)Ans / (sump * sumn) << endl;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0);
slv();
return 0;
}
/*
6
+ 7
- 2
- 5
+ 4
- 2
+ 6
*/
/*
3
+ 2
- 3
- 1
*/
/*
8
+ 34
+ 33
+ 26
- 34
- 38
+ 39
- 7
- 27
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3956kb
input:
3 + 2 - 3 - 1
output:
0.50000000000000
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
6 + 7 - 2 - 5 + 4 - 2 + 6
output:
0.88888888888889
result:
ok found '0.888888889', expected '0.888888889', error '0.000000000'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3832kb
input:
8 + 34 + 33 + 26 - 34 - 38 + 39 - 7 - 27
output:
0.62500000000000
result:
wrong answer 1st numbers differ - expected: '0.5625000', found: '0.6250000', error = '0.0625000'