QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#281456 | #2347. Traffic Blights | TadijaSebez | TL | 1474ms | 4112kb | C++14 | 1.9kb | 2023-12-10 05:59:02 | 2023-12-10 05:59:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ldb double
#define pb push_back
const int N=505;
const int M=101;
ldb ans[N];
int m[N],g[N],s[N];
const int X=2520;
bool good[N][M];
ldb Solve(int n){
ldb ans=0;
for(int ost=0;ost<X;ost++){
vector<pair<int,int>> all;
for(int i=1;i<=n;i++){
int g=__gcd(X,m[i]);
int o=ost%g;
for(int j=0;j<m[i]/g;j++)good[i][j]=false;
for(int j=0;j<::g[i];j++){
int x=(s[i]+j)%m[i];
if(x%g==o){
good[i][x/g]=true;
}
}
all.pb({m[i]/g,i});
}
sort(all.rbegin(),all.rend());
vector<bool> done(all.size(),false);
ldb now=1;
for(int i=0;i<all.size();i++){
if(!done[i]){
for(int j=i+1;j<all.size();j++){
if(all[i].first%all[j].first==0 && !done[j]){
int g1=m[all[i].second]/all[i].first;
int g2=m[all[j].second]/all[j].first;
int taken=0;
int val=ost%g1;
while(taken<all[i].first){
if(val%g2==ost%g2){
good[all[i].second][val/g1%all[i].first]&=good[all[j].second][val/g2%all[j].first];
taken++;
}
val+=g1;
//val%=m[all[i].second];
}
//for(int z=0;z<all[i].first;z++){
// good[all[i].second][z]&=good[all[j].second][(z*g1+ost%g1)/g2%all[j].first];
//}
done[j]=true;
}
}
int cnt=0;
for(int j=0;j<all[i].first;j++){
cnt+=good[all[i].second][j];
}
//printf("%i / %i\n",cnt,all[i].first);
now*=(ldb)cnt/all[i].first;
}
}
ans+=now;
}
return ans/X;
}
int main(){
int n;
scanf("%i",&n);
ans[0]=1;
for(int i=1;i<=n;i++){
int r,g,x;
scanf("%i %i %i",&x,&r,&g);
m[i]=r+g;
s[i]=((r-x)%m[i]+m[i])%m[i];
::g[i]=g;
ans[i]=Solve(i);
//printf("%.12f\n",ans[i]);
}
//printf("\n");
for(int i=1;i<=n+1;i++){
printf("%.12f\n",ans[i-1]-ans[i]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3812kb
Test #2:
score: 0
Accepted
time: 3ms
memory: 3816kb
Test #3:
score: 0
Accepted
time: 1ms
memory: 4104kb
Test #4:
score: 0
Accepted
time: 1ms
memory: 3888kb
Test #5:
score: 0
Accepted
time: 1ms
memory: 3972kb
Test #6:
score: 0
Accepted
time: 5ms
memory: 3812kb
Test #7:
score: 0
Accepted
time: 2ms
memory: 4112kb
Test #8:
score: 0
Accepted
time: 3ms
memory: 3972kb
Test #9:
score: 0
Accepted
time: 1ms
memory: 3844kb
Test #10:
score: 0
Accepted
time: 47ms
memory: 3808kb
Test #11:
score: 0
Accepted
time: 30ms
memory: 3892kb
Test #12:
score: 0
Accepted
time: 62ms
memory: 3884kb
Test #13:
score: 0
Accepted
time: 305ms
memory: 3976kb
Test #14:
score: 0
Accepted
time: 304ms
memory: 3832kb
Test #15:
score: 0
Accepted
time: 172ms
memory: 3816kb
Test #16:
score: 0
Accepted
time: 954ms
memory: 3760kb
Test #17:
score: 0
Accepted
time: 1474ms
memory: 3972kb
Test #18:
score: -100
Time Limit Exceeded