QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#100800 | #5377. $N$ 门问题 | lenlen | 0 | 10ms | 4444kb | C++14 | 1.7kb | 2023-04-28 10:19:58 | 2023-04-28 10:20:01 |
Judging History
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();
if(n>10) printf("0.000000\n");
else if(n==1) printf("1.000000\n");
else if(n==2) printf("0.500000\n");
else if(n==3) printf("0.666667\n");
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 2ms
memory: 3420kb
input:
1 2 3
output:
0.500000
result:
ok single line: '0.500000'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3632kb
input:
1 3 5
output:
0.666667
result:
ok single line: '0.666667'
Test #3:
score: -5
Wrong Answer
time: 1ms
memory: 3496kb
input:
1 4 5
output:
result:
wrong answer 1st lines differ - expected: '0.625000', found: ''
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 3632kb
input:
8 1 160005726539569 1 233 0 1 1 2947295521 1 686719856393 1 54289 1 12649337 1 37281334283719577
output:
1.000000
result:
wrong answer 1st lines differ - expected: 'error', found: '1.000000'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Wrong Answer
Test #57:
score: 25
Accepted
time: 2ms
memory: 3632kb
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: 0ms
memory: 3492kb
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: 3456kb
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: 0ms
memory: 3492kb
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: 3492kb
input:
2 543380932 999999999 451172165 1000000000
output:
0.000000
result:
ok single line: '0.000000'
Test #62:
score: 0
Accepted
time: 2ms
memory: 3428kb
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: 10ms
memory: 4444kb
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: 3ms
memory: 4228kb
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: -25
Wrong Answer
time: 10ms
memory: 4372kb
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: 'error', found: ''
Subtask #7:
score: 0
Skipped
Dependency #1:
0%