QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#356095#5105. Hand of the Free MarkedInfinityNSAC ✓420ms4124kbC++144.8kb2024-03-17 15:31:102024-03-17 15:31:10

Judging History

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

  • [2024-03-17 15:31:10]
  • 评测
  • 测评结果:AC
  • 用时:420ms
  • 内存:4124kb
  • [2024-03-17 15:31:10]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}

ld dv(vector<int> a,vector<int> a2,vector<int> b,vector<int> b2){
	for(auto p:a2)b.pb(p);
	for(auto p:b2)a.pb(p);
	ld p=1;
	while(a.size()||b.size()){
		if(a.size()==0||(p>=1&&b.size()!=0)){
			p/=b.back();
			b.pop_back();
		}
		else{
			p*=a.back();
			a.pop_back();
		}
	}
	return p;
}
vector<int> c,c2;
vector<pair<int,int>> chosen;
vector<int> cnt;
int k,m;
ld ans=0;
void calc(){
	vector<int> a,a2;
	for(auto p:chosen){
		for(int i=0;i<p.f;i++){
			a.pb(p.s-i);
			a2.pb(i+1);
		}
	}
	vector<pair<vector<int>,vector<int>>> bs;
	for(int i=0;i<chosen.size();i++){
		vector<int> b,b2;
		for(int j=0;j<chosen.size();j++){
			int c=chosen[j].f;
			if(i==j){
				c--;
			}
			for(int o=0;o<c;o++){
				b.pb(chosen[j].s-o);
				b2.pb(o+1);
			}
		}
		for(int j=0;j<k-1;j++){
			b.pb(j+1);
		}
		bs.pb({b,b2});
	}
	ld sum=0;
	for(auto p:bs){
		sum+=dv(p.f,p.s,a,a2);
	}
	//cout << chosen << sum << endl;
	//cout << a << a2 << endl;
	if(sum>=1){
		ans+=dv(a,a2,c,c2);
	}
	else{
		for(auto p:bs){
			ans+=dv(p.f,p.s,c,c2);
		}
	}
}
void solve(int i,int t){
	if(i==m){
		calc();
		return;
	}
	int st=0;
	if(i==m-1)st=t;
	for(int take=st;take<=min(cnt[i],t);take++){
		if(take){
			chosen.pb({take,cnt[i]});
		}
		solve(i+1,t-take);
		if(take){
			chosen.pop_back();
		}
	}
}
int main()
{
	scanf("%i %i",&k,&m);
	cnt.resize(m);
	int cc=0;
	for(int i=0;i<m;i++){
		scanf("%i",&cnt[i]);
		cc+=cnt[i];
	}
	for(int i=0;i<k;i++){
		c.pb(cc-i);
		c2.pb(i+1);
	}
	solve(0,k);
	printf("%.10Lf\n",ans);
	return 0;
}

详细

Test #1:

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

input:

3 3 2 1 2

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #2:

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

input:

3 4 1 3 1 15

output:

0.7719298246

result:

ok answer is 0.7719298246

Test #3:

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

input:

4 1 27

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #4:

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

input:

4 3 1 2 28

output:

0.9739710790

result:

ok answer is 0.9739710790

Test #5:

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

input:

4 3 1 3 28

output:

0.9772246941

result:

ok answer is 0.9772246941

Test #6:

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

input:

5 1 130

output:

0.9523809524

result:

ok answer is 0.9523809524

Test #7:

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

input:

5 3 2 16 200

output:

0.7490392123

result:

ok answer is 0.7490392123

Test #8:

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

input:

4 10 1 2 3 4 1 2 3 4 5 100

output:

0.6954998646

result:

ok answer is 0.6954998646

Test #9:

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

input:

4 10 1 20 3 4 1 2 40 4 5 500

output:

0.2435721816

result:

ok answer is 0.2435721816

Test #10:

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

input:

3 2 152333146 373955979

output:

0.0000000228

result:

ok answer is 0.0000000228

Test #11:

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

input:

2 5 263121 2244976 14139709 57922752 200667899

output:

0.0000000363

result:

ok answer is 0.0000000363

Test #12:

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

input:

2 9 8693409 192044828 270204 207696017 4714758 43866747 54411633 159493424 1230327

output:

0.0000000268

result:

ok answer is 0.0000000268

Test #13:

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

input:

5 2 368946153 140852305

output:

0.0000004708

result:

ok answer is 0.0000004708

Test #14:

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

input:

6 7 21894756 69672 6998541 209713 14912795 3044993 4001906

output:

0.0000985677

result:

ok answer is 0.0000985677

Test #15:

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

input:

7 8 10393835 5758 42813 141353298 4827 7467584 30955 5450

output:

0.0002531002

result:

ok answer is 0.0002531002

Test #16:

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

input:

9 2 510542963 107597808

output:

0.0011741015

result:

ok answer is 0.0011741015

Test #17:

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

input:

9 4 61285845 5006573 857873 164342879

output:

0.0062702500

result:

ok answer is 0.0062702500

Test #18:

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

input:

8 9 150817030 1785608 1799504 185570 765031 91189422 826565 162065 31840039

output:

0.0012989187

result:

ok answer is 0.0012989187

Test #19:

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

input:

3 3 303536168 13837393 495002513

output:

0.0000000222

result:

ok answer is 0.0000000222

Test #20:

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

input:

3 6 53418609 234629667 123823068 34111351 5030364 122184307

output:

0.0000000628

result:

ok answer is 0.0000000628

Test #21:

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

input:

2 8 367991 173352184 277736038 8490 1609033 14778992 46849 7751

output:

0.0000000342

result:

ok answer is 0.0000000342

Test #22:

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

input:

7 2 267723891 27011243

output:

0.0000342002

result:

ok answer is 0.0000342002

Test #23:

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

input:

7 4 142414601 5258379 6663526 395635619

output:

0.0000366564

result:

ok answer is 0.0000366564

Test #24:

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

input:

6 10 74360718 12028354 85290 298827 991561 26513484 13713894 241157 664292 69531

output:

0.0000558282

result:

ok answer is 0.0000558282

Test #25:

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

input:

8 2 248584022 141021009

output:

0.0002069789

result:

ok answer is 0.0002069789

Test #26:

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

input:

8 5 21702603 142314177 4721812 36026710 10702024

output:

0.0009356407

result:

ok answer is 0.0009356407

Test #27:

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

input:

8 10 167779 219592785 89060 377095564 169349 75686 382454 10537801 86060 487630

output:

0.0006624125

result:

ok answer is 0.0006624125

Test #28:

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

input:

2 1 2

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #29:

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

input:

2 1 1000000000

output:

0.0000000020

result:

ok answer is 0.0000000020

Test #30:

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

input:

2 2 1 1

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #31:

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

input:

2 2 1 999999999

output:

0.0000000040

result:

ok answer is 0.0000000040

Test #32:

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

input:

2 2 999999999 1

output:

0.0000000040

result:

ok answer is 0.0000000040

Test #33:

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

input:

2 2 500000000 500000000

output:

0.0000000040

result:

ok answer is 0.0000000040

Test #34:

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

input:

2 3 1 1 1

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #35:

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

input:

2 3 1 3 2

output:

0.9333333333

result:

ok answer is 0.9333333333

Test #36:

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

input:

2 3 1 999999997 2

output:

0.0000000060

result:

ok answer is 0.0000000060

Test #37:

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

input:

2 10 1 1 1 1 1 1 1 1 1 1

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #38:

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

input:

2 10 1 2 1 2 1 2 1 2 1 2

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #39:

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

input:

2 10 1 2 3 4 5 6 7 8 9 10

output:

0.3629629630

result:

ok answer is 0.3629629630

Test #40:

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

input:

2 10 1 1 1 1 1 999999980 2 2 2 2

output:

0.0000000200

result:

ok answer is 0.0000000200

Test #41:

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

input:

3 1 3

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #42:

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

input:

3 1 500000000

output:

0.0000000120

result:

ok answer is 0.0000000120

Test #43:

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

input:

3 2 1 2

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #44:

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

input:

3 2 999999998 1

output:

0.0000000090

result:

ok answer is 0.0000000090

Test #45:

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

input:

3 3 3 3 3

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #46:

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

input:

3 3 5 12 1

output:

0.7965686275

result:

ok answer is 0.7965686275

Test #47:

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

input:

3 10 99999990 99999991 99999992 99999993 99999994 99999995 99999996 99999997 99999998 99999999

output:

0.0000000600

result:

ok answer is 0.0000000600

Test #48:

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

input:

10 1 10

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #49:

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

input:

10 1 500000000

output:

0.0072576001

result:

ok answer is 0.0072576001

Test #50:

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

input:

10 1 1000000000

output:

0.0036288000

result:

ok answer is 0.0036288000

Test #51:

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

input:

10 2 5 5

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #52:

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

input:

10 2 10 5

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #53:

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

input:

10 2 999999999 1

output:

0.0036288100

result:

ok answer is 0.0036288100

Test #54:

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

input:

10 2 500000000 500000000

output:

0.0072576001

result:

ok answer is 0.0072576001

Test #55:

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

input:

10 2 499999999 500000001

output:

0.0072576001

result:

ok answer is 0.0072576001

Test #56:

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

input:

10 3 10 10 10

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #57:

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

input:

10 3 11 10 10

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #58:

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

input:

10 3 11 999999970 10

output:

0.0036290094

result:

ok answer is 0.0036290094

Test #59:

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

input:

10 3 499999990 2 499999999

output:

0.0072576200

result:

ok answer is 0.0072576200

Test #60:

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

input:

10 3 333333333 333333333 333333333

output:

0.0108864001

result:

ok answer is 0.0108864001

Test #61:

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

input:

10 10 1 1 1 1 1 1 1 1 1 1

output:

1.0000000000

result:

ok answer is 1.0000000000

Test #62:

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

input:

10 10 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000

output:

0.0362880003

result:

ok answer is 0.0362880003

Test #63:

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

input:

10 10 99999999 99999998 99999997 99999996 99999995 99999994 99999993 99999992 99999991 99999990

output:

0.0362880023

result:

ok answer is 0.0362880023

Test #64:

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

input:

10 10 1 2 1 2 1 2 1 2 999999980 3

output:

0.0036289496

result:

ok answer is 0.0036289496

Extra Test:

score: 0
Extra Test Passed