QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#643229 | #6609. Scholomance Academy | ChensenCHX | WA | 2ms | 10060kb | C++23 | 2.8kb | 2024-10-15 19:58:45 | 2024-10-15 19:58:47 |
Judging History
answer
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
#define Mid (l+r)/2
#define Ls i<<1
#define Rs i<<1|1
#define Lson Ls,l,Mid
#define Rson Rs,Mid+1,r
#define For(i,a,b) for(int i=a;i<=b;i++)
#define FOr(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
//tree<ll,null_type,std::less<ll>,splay_tree_tag,tree_order_statistics_node_update>sp;//红黑树是rb_tree_tag
/*
inline int read()
{
int x = 0, f = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -f; c = getchar(); }
while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
return x * f;
}
*/
//parameter begin
#define maxN 1000010
#define M 1000000009
ll n,b[maxN],len,tp,tn,fp,fn,realp,realn,cnt;
long double tpr[maxN],fpr[maxN];
typedef struct
{
ll s;
char c;
}SC;
SC a[maxN];
//parameter end
//function begin
bool cmp(SC& x,SC& y)
{
return x.s<y.s;
}
ll findx(ll x)
{
return lower_bound(b+1,b+len+1,x)-b;
}
//function end
int main ()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
//main begin
cin>>n;
fp=tp=fn=tn=0;
cnt=0;
For(i,1,n)
{
cin>>a[i].c>>a[i].s;
b[i]=a[i].s;
if(a[i].c=='+') tp++;
else fp++;
}
if(tp == n || tp == n){
printf("0");
return 0;
}
sort(b+1,b+n+1);
len=unique(b+1,b+n+1)-b-1;
sort(a+1,a+n+1,cmp);
tpr[0]=(long double)tp/((long double)tp+(long double)fn),fpr[0]=(long double)fp/((long double)tn+(long double)fp);
For(i,1,n)
{
if(a[i].c=='-')
{
fp--;
tn++;
}
if(a[i-1].c=='+')
{
tp--;
fn++;
}
if(a[i+1].s==a[i].s) continue;
++cnt;
tpr[cnt]=(long double)tp/((long double)tp+(long double)fn),fpr[cnt]=(long double)fp/((long double)tn+(long double)fp);
//cout<<fpr[cnt]<<' '<<tpr[cnt]<<endl;
}
++cnt;
tpr[cnt]=fpr[cnt]=(long double)1;
fpr[0]=tpr[0]=(long double)1;
long double sum = 0;
for(int i=cnt-1; i>0; i--){
sum = sum + (fpr[i-1]-fpr[i])*tpr[i];
//cout<<fpr[i]<<' '<<tpr[i]<<' '<<sum<<endl;
}
//cout<<fpr[0]<<' '<<tpr[0]<<' '<<sum<<endl;
if(fabs(fpr[1])<1e-12 && fabs(tpr[1]-1)<1e12)
cout<<0;
else
cout << fixed << setprecision(12) << sum <<"\n";
//main end
return 0;
}
/*
3
+ 2
- 3
- 1
6
+ 7
- 2
- 5
+ 4
- 2
+ 6
8
+ 34
+ 33
+ 26
- 34
- 38
+ 39
- 7
- 27
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 10060kb
input:
3 + 2 - 3 - 1
output:
0.500000000000
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 10004kb
input:
6 + 7 - 2 - 5 + 4 - 2 + 6
output:
0.888888888889
result:
ok found '0.888888889', expected '0.888888889', error '0.000000000'
Test #3:
score: 0
Accepted
time: 2ms
memory: 10056kb
input:
8 + 34 + 33 + 26 - 34 - 38 + 39 - 7 - 27
output:
0.562500000000
result:
ok found '0.562500000', expected '0.562500000', error '0.000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 9820kb
input:
2 + 12345135 - 12345135
output:
0
result:
ok found '0.000000000', expected '0.000000000', error '-0.000000000'
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 9740kb
input:
2 + 4 - 3
output:
0
result:
wrong answer 1st numbers differ - expected: '1.0000000', found: '0.0000000', error = '1.0000000'