QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#825480#9778. Brotatoucup-team1134#WA 536ms196604kbC++233.0kb2024-12-21 19:41:042024-12-21 19:41:05

Judging History

This is the latest submission verdict.

  • [2024-12-21 19:41:05]
  • Judged
  • Verdict: WA
  • Time: 536ms
  • Memory: 196604kb
  • [2024-12-21 19:41:04]
  • Submitted

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 long double
ld dp[MAX][123];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,K;
    ld P;cin>>N>>K>>P;
    ll pp=roundl(P*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--){
            dp[i][j]=(ld)(dp[i+1][j]*qq+dp[i][j-1]*pp+rr)/rr;
        }
        ld l=0,r=dp[0][j-1];
        for(int q=0;q<80;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;
            }
            ld s=dp[R][j];
            for(int i=L;i>=0;i--){
                s=(ld)(s*qq+m*pp+rr)/rr;
            }
            if(s>m) l=m;
            else r=m;
        }
        /*
        int L=0,R=N;
        while(R-L>1){
            int M=(L+R)/2;
        }
        ld l=0,r=1e14;
        for(int q=0;q<80;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;
            }
            for(int i=R;i>=1;i--){
                dp[i][j]=(ld)(dp[i+1][j]*qq+min(dp[i][j-1],m)*pp+rr)/rr;
            }
            ld z=(dp[1][j]*qq+m*pp+rr)/rr;
            //for(int i=0;i<=N;i++) cout<<m<<" "<<i<<" "<<dp[i][j]<<endl;
            if(z>m) l=m;
            else r=m;
        }
         */
        ld m=(l+r)/2;
        for(int i=N-1;i>=1;i--){
            dp[i][j]=(ld)(dp[i+1][j]*qq+min(dp[i][j-1],m)*pp+rr)/rr;
        }
        dp[0][j]=(l+r)/2;
        //for(int i=0;i<=N;i++) cout<<dp[i][j]<<endl;
        //cout<<fixed<<setprecision(25)<<(l+r)/2<<endl;
    }
    
    cout<<fixed<<setprecision(25)<<dp[0][K]<<endl;
}



詳細信息

Test #1:

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

input:

5 0
0.5

output:

61.9999999999999999965305530

result:

ok found '62.000000000', expected '62.000000000', error '0.000000000'

Test #2:

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

input:

5 1
0.5

output:

46.9999999999999999722444244

result:

ok found '47.000000000', expected '47.000000000', error '0.000000000'

Test #3:

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

input:

10000 0
0.002

output:

247489700298.2537139505147933959960938

result:

ok found '247489700298.253723145', expected '247489700298.253692627', error '0.000000000'

Test #4:

score: -100
Wrong Answer
time: 536ms
memory: 196604kb

input:

100000 10
0.0002

output:

38767507205.0245004594326019287109375

result:

wrong answer 1st numbers differ - expected: '38767507133.2322159', found: '38767507205.0244980', error = '0.0000000'