QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#757796#6609. Scholomance Academydad11WA 245ms19508kbC++141.6kb2024-11-17 13:33:362024-11-17 13:33:45

Judging History

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

  • [2024-11-17 13:33:45]
  • 评测
  • 测评结果:WA
  • 用时:245ms
  • 内存:19508kb
  • [2024-11-17 13:33:36]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
#define int long long
const int N=1e6+10;

struct node
{
    char op;
    int s;
}x[N];

int cmp(node a,node b){
	if(a.s == b.s){
		return a.op < b.op;
	}else
		return a.s < b.s;
}

int lcm(int a,int b)
{
    return a*b/__gcd(a,b);
}

signed main()
{
    int n;
    cin>>n;
    getchar();
    int s1=0,s2=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i].op>>x[i].s;
         getchar();
        if(x[i].op=='-') s2++;
        else s1++;
    }
    sort(x+1,x+n+1,cmp);
    // for(int i=1;i<=n;i++) cout<<x[i].op<<" "<<x[i].s<<endl;
    int fenzi=0,fenmu=1;
    int p=1,q=1;
    for(int i=1;i<=n;i++)
    {
        if(x[i].op=='-')
        {
            // ans+=t*1.0/s2;
            int p1=p,q1=q*s2;
            int d=__gcd(p1,q1);;
            p1/=d,q1/=d;
            int now=lcm(fenmu,q1);
            d=now/fenmu;
            fenzi*=d;
            fenmu=now;
            d=now/q1;
            p1*=d;
            q1=now;
            fenzi+=p1;
            d=__gcd(fenzi,fenmu);
            fenzi/=d;
            fenmu/=d;
        } 
        else 
        {
            // t=t-1.0/s1;
            int now=lcm(q,s1);
            int d=now/q;
            p*=d;
            q=now;
            p-=now/s1;
            if(p!=0)
            {
                d=__gcd(p,q);
                p/=d;
                q/=d;
            }
            else p=0,q=1;
        }
    }
    double ans=(double)(fenzi*1.0)/(double)(fenmu*1.0);
    printf("%.10lf\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3804kb

input:

3
+ 2
- 3
- 1

output:

0.5000000000

result:

ok found '0.500000000', expected '0.500000000', error '0.000000000'

Test #2:

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

input:

6
+ 7
- 2
- 5
+ 4
- 2
+ 6

output:

0.8888888889

result:

ok found '0.888888889', expected '0.888888889', error '0.000000000'

Test #3:

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

input:

8
+ 34
+ 33
+ 26
- 34
- 38
+ 39
- 7
- 27

output:

0.5625000000

result:

ok found '0.562500000', expected '0.562500000', error '0.000000000'

Test #4:

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

input:

2
+ 12345135
- 12345135

output:

0.0000000000

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #5:

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

input:

2
+ 4
- 3

output:

1.0000000000

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #6:

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

input:

2
- 3
+ 4

output:

1.0000000000

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #7:

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

input:

2
- 12
+ 11

output:

0.0000000000

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #8:

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

input:

2
+ 7
- 9

output:

0.0000000000

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #9:

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

input:

2
- 4
+ 4

output:

0.0000000000

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #10:

score: 0
Accepted
time: 216ms
memory: 19476kb

input:

1000000
+ 1
- 1
- 1
- 1
+ 1
- 1
+ 1
- 1
- 1
+ 1
+ 1
- 1
+ 1
- 1
- 1
+ 1
+ 1
+ 1
+ 1
+ 1
- 1
+ 1
+ 1
- 1
- 1
- 1
+ 1
- 1
+ 1
- 1
+ 1
- 1
+ 1
+ 1
+ 1
+ 1
- 1
+ 1
- 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
- 1
+ 1
+ 1
+ 1
+ 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.0000000000

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #11:

score: -100
Wrong Answer
time: 245ms
memory: 19508kb

input:

999999
+ 2
- 1
+ 1
- 2
+ 2
- 1
- 1
+ 1
- 2
+ 2
- 1
- 2
+ 1
- 2
- 1
+ 2
- 2
- 1
- 1
- 2
+ 2
+ 1
- 1
- 2
+ 2
+ 1
- 1
- 1
+ 2
- 2
+ 2
- 1
+ 1
+ 1
- 2
+ 2
+ 1
+ 2
+ 1
+ 2
- 2
+ 1
- 2
+ 1
- 2
+ 2
+ 2
- 1
- 1
- 1
+ 2
+ 1
+ 2
- 1
- 1
- 2
+ 2
- 1
+ 2
- 2
- 2
+ 1
+ 1
+ 1
+ 2
+ 2
+ 2
+ 2
+ 1
- 2
- 2
- 1
- 1
-...

output:

0.0000000000

result:

wrong answer 1st numbers differ - expected: '0.2497381', found: '0.0000000', error = '0.2497381'