QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#825603 | #9778. Brotato | ucup-team1134# | WA | 1ms | 3860kb | C++23 | 3.1kb | 2024-12-21 20:44:52 | 2024-12-21 20:45:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;
#define ld _Float128
ld dp[MAX][123];
pair<ld,ld> db[77];
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
ll N,K;
double ppp;
ld P;cin>>N>>K>>ppp;
P=ppp;
ll pp=roundl(ppp*10000),qq=10000-pp,rr=10000;
chmin(K,120LL);
for(int j=0;j<=K;j++) dp[N][j]=0;
dp[0][0]=0;
for(int i=N-1;i>=0;i--){
dp[0][0]+=1.0l;
dp[0][0]/=qq;
dp[0][0]*=rr;
}
for(int i=N-1;i>=1;i--){
dp[i][0]=(dp[i+1][0]*qq+dp[0][0]*pp+rr)/rr;
}
//cout<<fixed<<setprecision(25)<<dp[0][0]<<endl;
for(int j=1;j<=K;j++){
for(int i=N-1;i>=0;i--){
if(dp[i+1][j]<1e5){
long double s=((long double)(dp[i+1][j])*(qq)+(long double)(dp[i][j-1])*(pp))/(long double)rr+1;
dp[i][j]=s;
}else{
dp[i][j]=(dp[i+1][j]*qq+dp[i][j-1]*pp+rr)/rr;
}
}
ld l=0,r=1e14;
for(int q=0;q<100;q++){
ld m=(l+r)/2;
int L=0,R=N;
while(R-L>1){
int M=(L+R)/2;
if(dp[M][j-1]<m) R=M;
else L=M;
}
db[0]=mp((ld)(qq)/rr,(ld)(m*pp)/rr+1);
for(int s=1;s<=40;s++){
auto [a,b]=db[s-1];
db[s]=mp(a*a,a*b+b);
}
ld s=dp[R][j];
int cn=L+1;
for(int t=0;t<=20;t++){
if(cn&(1<<t)){
s=db[t].fi*s+db[t].se;
}
}
if(s>m) l=m;
else r=m;
}
ld m=(l+r)/2;
ld ad=m*pp/rr+1;
for(int i=N-1;i>=0;i--){
if(dp[i][j-1]>m){
if(dp[i+1][j]<1e5&&ad<1e5){
long double s=((long double)(dp[i+1][j])*qq/(long double)rr+(ll)(ad));
dp[i][j]=s;
}else{
dp[i][j]=dp[i+1][j]*qq/rr+ad;
}
}
}
//for(int i=0;i<=N;i++) cout<<dp[i][j]<<endl;
//cout<<fixed<<setprecision(25)<<(l+r)/2<<endl;
}
cout<<fixed<<setprecision(25)<<(long double)(dp[0][K])<<endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
5 0 0.5
output:
62.0000000000000000000000000
result:
ok found '62.000000000', expected '62.000000000', error '0.000000000'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3860kb
input:
5 1 0.5
output:
46.0625000000000000000000000
result:
wrong answer 1st numbers differ - expected: '47.0000000', found: '46.0625000', error = '0.0199468'