QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#356089 | #5105. Hand of the Free Marked | InfinityNS | WA | 1ms | 3876kb | C++14 | 4.8kb | 2024-03-17 15:27:43 | 2024-03-17 15:27:45 |
Judging History
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;
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<=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: 0
Wrong Answer
time: 1ms
memory: 3876kb
input:
3 3 2 1 2
output:
1.8000000000
result:
wrong answer expected 1.0000000000, found 1.8000000000