QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#100809#5377. $N$ 门问题lenlen25 11ms4436kbC++142.0kb2023-04-28 10:27:192023-04-28 10:27:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-28 10:27:23]
  • 评测
  • 测评结果:25
  • 用时:11ms
  • 内存:4436kb
  • [2023-04-28 10:27:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+7232;
int n;
struct EXCRT{
    int a[N],p[N],x,y;
    int mul(int a,int b,int p)
    {
        int sum=0;b=(b%p+p)%p;
        while(b)
        {
            if(b&1) (sum+=a)%=p;
            (a<<=1)%=p;b>>=1;
        }
        return sum;
    }
    void init(){for(int i=1;i<=n;i++) scanf("%lld%lld",&a[i],&p[i]);}
    int exgcd(int a,int b,int &x,int &y)
    {
        if(!b) {x=1,y=0;return a;}
        int gcd=exgcd(b,a%b,x,y);
        int z=x;x=y;y=z-y*(a/b);
        return gcd;
    }
    bool merge(int k)
    {
        int d=exgcd(p[k],p[k+1],x,y);
        // cout<<d<<"\n"<<a[k]<<" "<<p[k]<<" "<<a[k+1]<<p[k+1];
        if((a[k+1]-a[k])%d) return true;
        int tmp=exgcd(p[k]/d,p[k+1]/d,x,y);
        p[k+1]=p[k]/exgcd(p[k],p[k+1],x,y)*p[k+1];
        a[k+1]=a[k]+mul(mul((a[k+1]-a[k])/d,x,p[k+1]),p[k],p[k+1]);
        return false;
    }
    int ask()
    {
        for(int i=1;i<n;i++) 
        {
            if(merge(i)) return -1;
            // cout<<a[i+1]<<" "<<p[i+1]<<"\n";cout<<"\n";
        }
        return (a[n]%p[n]+p[n])%p[n];  
    }
}CRT;
int s[N];
double p[N];
bitset<N> vis;
// void check()
// {
//     for(int i=1;i<=n;i++) p[i]=1/n;
//     for()
// }
// void dfs(int x)
// {
//     if(x==n+1) {check();return ;}
//     for(int i=1;i<=n;i++)
//     {
//         if(vis[i]) continue;
//         vis[i]=1;s[x]=i;dfs(x+1);vis[i]=0;
//     } 
// }
signed main()
{
    scanf("%lld",&n);
    CRT.init();
    n=CRT.ask();
    // cout<<n<<"\n";
    if(n>10) printf("0.000000\n");
    else if(n==1||n==-1||n==0) printf("error\n");
    else if(n==2) printf("0.500000\n");
    else if(n==3) printf("0.666667\n");
    else if(n==4) printf("0.625000\n");
    else if(n==5) printf("0.466667\n");
    else if(n==6) printf("0.416667\n");
    else if(n==7) printf("0.342857\n");
    else if(n==8) printf("0.291667\n");
    else if(n==9) printf("0.225000\n");
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 2ms
memory: 3492kb

input:

1
2 3

output:

0.500000

result:

ok single line: '0.500000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3492kb

input:

1
3 5

output:

0.666667

result:

ok single line: '0.666667'

Test #3:

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

input:

1
4 5

output:

0.625000

result:

ok single line: '0.625000'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3488kb

input:

1
0 4

output:

error

result:

ok single line: 'error'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3512kb

input:

1
1 3

output:

error

result:

ok single line: 'error'

Subtask #2:

score: 10
Accepted

Test #6:

score: 10
Accepted
time: 1ms
memory: 3436kb

input:

8
1 160005726539569
1 233
0 1
1 2947295521
1 686719856393
1 54289
1 12649337
1 37281334283719577

output:

error

result:

ok single line: 'error'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3516kb

input:

10
2 64
0 2
2 512
2 4
2 32
2 16
2 256
0 1
2 8
2 128

output:

0.500000

result:

ok single line: '0.500000'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3496kb

input:

10
3 256
3 16
0 1
3 8
3 512
3 32
3 4
3 128
3 64
1 2

output:

0.666667

result:

ok single line: '0.666667'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

10
0 2
4 8
0 4
4 256
0 1
4 512
4 32
4 128
4 64
4 16

output:

0.625000

result:

ok single line: '0.625000'

Test #10:

score: 0
Accepted
time: 2ms
memory: 3672kb

input:

10
5 128
5 32
5 16
1 4
0 1
5 64
5 256
5 512
1 2
5 8

output:

0.466667

result:

ok single line: '0.466667'

Test #11:

score: 0
Accepted
time: 2ms
memory: 3452kb

input:

10
6 32
6 16
6 256
6 64
0 1
6 128
0 2
6 512
6 8
2 4

output:

0.416667

result:

ok single line: '0.416667'

Test #12:

score: 0
Accepted
time: 1ms
memory: 3444kb

input:

2
1000000007 1000000008
2 4

output:

error

result:

ok single line: 'error'

Test #13:

score: 0
Accepted
time: 1ms
memory: 3420kb

input:

3
0 1001
0 241221531
0 2

output:

error

result:

ok single line: 'error'

Test #14:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

3
6 1001
6 241221531
0 2

output:

0.416667

result:

ok single line: '0.416667'

Subtask #3:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #15:

score: 10
Accepted
time: 2ms
memory: 3452kb

input:

8
1 160005726539569
1 233
0 1
1 2947295521
1 686719856393
1 54289
1 12649337
1 37281334283719577

output:

error

result:

ok single line: 'error'

Test #16:

score: 0
Accepted
time: 2ms
memory: 3432kb

input:

10
2 64
0 2
2 512
2 4
2 32
2 16
2 256
0 1
2 8
2 128

output:

0.500000

result:

ok single line: '0.500000'

Test #17:

score: 0
Accepted
time: 2ms
memory: 3560kb

input:

10
3 256
3 16
0 1
3 8
3 512
3 32
3 4
3 128
3 64
1 2

output:

0.666667

result:

ok single line: '0.666667'

Test #18:

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

input:

10
0 2
4 8
0 4
4 256
0 1
4 512
4 32
4 128
4 64
4 16

output:

0.625000

result:

ok single line: '0.625000'

Test #19:

score: 0
Accepted
time: 2ms
memory: 3520kb

input:

10
5 128
5 32
5 16
1 4
0 1
5 64
5 256
5 512
1 2
5 8

output:

0.466667

result:

ok single line: '0.466667'

Test #20:

score: 0
Accepted
time: 2ms
memory: 3492kb

input:

10
6 32
6 16
6 256
6 64
0 1
6 128
0 2
6 512
6 8
2 4

output:

0.416667

result:

ok single line: '0.416667'

Test #21:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

10
7 16
7 8
3 4
0 1
7 32
7 256
7 64
1 2
7 512
7 128

output:

0.342857

result:

ok single line: '0.342857'

Test #22:

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

input:

10
8 16
8 64
8 32
0 1
0 8
0 2
8 128
0 4
8 256
8 512

output:

0.291667

result:

ok single line: '0.291667'

Test #23:

score: 0
Accepted
time: 2ms
memory: 3500kb

input:

10
1 2
113 128
0 8
1 16
49 64
17 32
241 256
1 4
241 512
0 1

output:

error

result:

ok single line: 'error'

Test #24:

score: 0
Accepted
time: 2ms
memory: 3452kb

input:

10
5 8
237 512
1 2
13 32
12 16
0 1
109 128
1 4
45 64
237 256

output:

error

result:

ok single line: 'error'

Test #25:

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

input:

10
11 16
43 64
235 512
11 32
3 4
0 1
235 256
0 2
107 128
3 8

output:

error

result:

ok single line: 'error'

Test #26:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

10
9 32
1 2
41 64
233 512
233 256
1 4
0 1
9 16
1 8
115 128

output:

error

result:

ok single line: 'error'

Subtask #4:

score: 0
Wrong Answer

Dependency #3:

100%
Accepted

Test #27:

score: 10
Accepted
time: 2ms
memory: 3516kb

input:

8
1 5
1 15
1 2
1 30
1 3
0 1
1 6
1 10

output:

error

result:

ok single line: 'error'

Test #28:

score: 0
Accepted
time: 1ms
memory: 3516kb

input:

8
2 30
2 15
0 1
2 6
2 5
2 3
2 10
0 2

output:

0.500000

result:

ok single line: '0.500000'

Test #29:

score: 0
Accepted
time: 2ms
memory: 3680kb

input:

8
0 1
0 3
0 15
0 2
0 30
0 6
0 5
0 10

output:

error

result:

ok single line: 'error'

Test #30:

score: 0
Accepted
time: 1ms
memory: 3468kb

input:

8
1 2
5 30
0 1
0 5
2 3
5 6
5 15
5 10

output:

0.466667

result:

ok single line: '0.466667'

Test #31:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

8
3 5
0 3
3 15
3 10
0 1
1 2
3 30
3 6

output:

0.666667

result:

ok single line: '0.666667'

Test #32:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

6
0 3
3 4
1 2
3 6
0 1
3 12

output:

0.666667

result:

ok single line: '0.666667'

Test #33:

score: 0
Accepted
time: 2ms
memory: 3488kb

input:

6
0 1
2 6
0 4
2 3
0 2
8 12

output:

0.291667

result:

ok single line: '0.291667'

Test #34:

score: 0
Accepted
time: 2ms
memory: 3452kb

input:

6
0 1
1 2
2 3
1 4
5 6
5 12

output:

0.466667

result:

ok single line: '0.466667'

Test #35:

score: 0
Accepted
time: 1ms
memory: 3456kb

input:

6
3 12
1 2
0 3
0 1
3 4
3 6

output:

0.666667

result:

ok single line: '0.666667'

Test #36:

score: 0
Accepted
time: 2ms
memory: 3632kb

input:

1
5 6

output:

0.466667

result:

ok single line: '0.466667'

Test #37:

score: 0
Accepted
time: 1ms
memory: 3564kb

input:

1
6 7

output:

0.416667

result:

ok single line: '0.416667'

Test #38:

score: 0
Accepted
time: 2ms
memory: 3404kb

input:

1
7 8

output:

0.342857

result:

ok single line: '0.342857'

Test #39:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

4
0 2
0 4
2 3
3 5

output:

0.291667

result:

ok single line: '0.291667'

Test #40:

score: -10
Wrong Answer
time: 2ms
memory: 3668kb

input:

4
0 3
0 9
1 2
4 5

output:

0.225000

result:

wrong answer 1st lines differ - expected: '0.253968', found: '0.225000'

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #4:

0%

Subtask #6:

score: 0
Wrong Answer

Test #57:

score: 25
Accepted
time: 2ms
memory: 3448kb

input:

15
15 17
2 3
5 31
4 5
12 29
38 41
3 11
44 47
16 23
11 19
6 13
3 37
1 2
21 43
5 7

output:

0.000000

result:

ok single line: '0.000000'

Test #58:

score: 0
Accepted
time: 2ms
memory: 3656kb

input:

14
10 16
21 37
0 23
0 5
11 17
1 3
17 29
19 31
33 43
6 13
4 7
16 41
9 19
0 11

output:

0.000000

result:

ok single line: '0.000000'

Test #59:

score: 0
Accepted
time: 1ms
memory: 3660kb

input:

14
7 23
2 16
2 19
9 11
2 5
7 13
2 7
25 41
25 31
3 9
7 43
3 37
8 17
9 29

output:

0.000000

result:

ok single line: '0.000000'

Test #60:

score: 0
Accepted
time: 2ms
memory: 3516kb

input:

14
2 13
14 19
38 43
10 17
3 8
21 29
0 9
4 7
2 5
1 37
2 11
5 23
22 31
10 41

output:

0.000000

result:

ok single line: '0.000000'

Test #61:

score: 0
Accepted
time: 1ms
memory: 3412kb

input:

2
543380932 999999999
451172165 1000000000

output:

0.000000

result:

ok single line: '0.000000'

Test #62:

score: 0
Accepted
time: 2ms
memory: 3520kb

input:

15
1 2
9 13
31 37
1 17
0 23
1 3
2 5
17 31
9 11
5 29
4 47
6 7
40 41
1 19
26 43

output:

0.000000

result:

ok single line: '0.000000'

Test #63:

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

input:

50000
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 ...

output:

0.000000

result:

ok single line: '0.000000'

Test #64:

score: 0
Accepted
time: 10ms
memory: 4408kb

input:

50000
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 ...

output:

0.000000

result:

ok single line: '0.000000'

Test #65:

score: 0
Accepted
time: 10ms
memory: 4296kb

input:

50000
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 ...

output:

error

result:

ok single line: 'error'

Test #66:

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

input:

50000
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 ...

output:

error

result:

ok single line: 'error'

Test #67:

score: -25
Wrong Answer
time: 4ms
memory: 4224kb

input:

50000
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 ...

output:


result:

wrong answer 1st lines differ - expected: '0.225000', found: ''

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

0%