QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#281465#2347. Traffic BlightsTadijaSebezAC ✓1855ms4180kbC++142.1kb2023-12-10 06:15:242023-12-10 06:15:25

Judging History

This is the latest submission verdict.

  • [2023-12-10 06:15:25]
  • Judged
  • Verdict: AC
  • Time: 1855ms
  • Memory: 4180kb
  • [2023-12-10 06:15:24]
  • Submitted

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];
vector<pair<int,int>> best;

void Solve(int ost, int n){
	vector<pair<int,int>> all=best;
	for(int i=n;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]=0;
		for(int j=0;j<::g[i];j++){
			int x=(s[i]+j)%m[i];
			if(x%g==o){
				good[i][x/g]=1;
			}
		}
		all.pb({m[i]/g,i});
	}
	best.clear();
	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 g3=__gcd(g1,g2);
					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[i].second][val/g1%all[i].first]&good[all[j].second][val/g2%all[j].first];
							taken++;
							val+=g1*g2/g3;
						}else{
							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;
			best.pb(all[i]);
		}
	}
	ans[n]+=now;
}
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;
		//printf("%.12f\n",ans[i]);
	}
	for(int ost=0;ost<X;ost++){
		best.clear();
		for(int i=1;i<=n;i++){
			Solve(ost,i);
		}
	}
	for(int i=1;i<=n;i++){
		ans[i]/=X;
	}
	//printf("\n");
	for(int i=1;i<=n+1;i++){
		printf("%.12f\n",ans[i-1]-ans[i]);
	}
	return 0;
}

Details

Test #1:

score: 100
Accepted
time: 1ms
memory: 3896kb

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

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

Test #9:

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

Test #10:

score: 0
Accepted
time: 3ms
memory: 3836kb

Test #11:

score: 0
Accepted
time: 3ms
memory: 3892kb

Test #12:

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

Test #13:

score: 0
Accepted
time: 19ms
memory: 3840kb

Test #14:

score: 0
Accepted
time: 23ms
memory: 3840kb

Test #15:

score: 0
Accepted
time: 12ms
memory: 3956kb

Test #16:

score: 0
Accepted
time: 37ms
memory: 3888kb

Test #17:

score: 0
Accepted
time: 50ms
memory: 4124kb

Test #18:

score: 0
Accepted
time: 52ms
memory: 4100kb

Test #19:

score: 0
Accepted
time: 44ms
memory: 3832kb

Test #20:

score: 0
Accepted
time: 23ms
memory: 3840kb

Test #21:

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

Test #22:

score: 0
Accepted
time: 283ms
memory: 3880kb

Test #23:

score: 0
Accepted
time: 14ms
memory: 4132kb

Test #24:

score: 0
Accepted
time: 330ms
memory: 3888kb

Test #25:

score: 0
Accepted
time: 8ms
memory: 3836kb

Test #26:

score: 0
Accepted
time: 219ms
memory: 4180kb

Test #27:

score: 0
Accepted
time: 12ms
memory: 4128kb

Test #28:

score: 0
Accepted
time: 368ms
memory: 3980kb

Test #29:

score: 0
Accepted
time: 1709ms
memory: 3884kb

Test #30:

score: 0
Accepted
time: 1121ms
memory: 3948kb

Test #31:

score: 0
Accepted
time: 101ms
memory: 3888kb

Test #32:

score: 0
Accepted
time: 101ms
memory: 3984kb

Test #33:

score: 0
Accepted
time: 147ms
memory: 3944kb

Test #34:

score: 0
Accepted
time: 585ms
memory: 3984kb

Test #35:

score: 0
Accepted
time: 1610ms
memory: 3900kb

Test #36:

score: 0
Accepted
time: 1667ms
memory: 3944kb

Test #37:

score: 0
Accepted
time: 1391ms
memory: 3936kb

Test #38:

score: 0
Accepted
time: 1536ms
memory: 4040kb

Test #39:

score: 0
Accepted
time: 1535ms
memory: 3956kb

Test #40:

score: 0
Accepted
time: 1390ms
memory: 3888kb

Test #41:

score: 0
Accepted
time: 1402ms
memory: 3836kb

Test #42:

score: 0
Accepted
time: 296ms
memory: 3888kb

Test #43:

score: 0
Accepted
time: 331ms
memory: 4004kb

Test #44:

score: 0
Accepted
time: 1529ms
memory: 4044kb

Test #45:

score: 0
Accepted
time: 1505ms
memory: 3944kb

Test #46:

score: 0
Accepted
time: 1855ms
memory: 3988kb

Test #47:

score: 0
Accepted
time: 942ms
memory: 3816kb

Test #48:

score: 0
Accepted
time: 408ms
memory: 3948kb

Test #49:

score: 0
Accepted
time: 1682ms
memory: 3944kb

Test #50:

score: 0
Accepted
time: 145ms
memory: 3888kb