QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#489162#8511. Greek Casinoucup-team1600#WA 0ms3780kbC++172.3kb2024-07-24 18:43:502024-07-24 18:43:50

Judging History

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

  • [2024-07-24 18:43:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3780kb
  • [2024-07-24 18:43:50]
  • 提交

answer

//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")

#include <bits/stdc++.h>

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

template<typename T>
bool umin(T &a, T b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool umax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifdef KIVI
#define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl

template<class ...Ts>
auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }

#else
#define DEBUG while (false)
#define LOG(...)
#endif

mt19937 rng(4242);

const int max_n = -1, inf = 1000111222;

void solve() {
    int n;
    cin >> n;
    vector<ld> w(n + 1), w_over_divs(n + 1);
    ld sumw = 0;
    for(int i = 1; i <= n; i++) {
        cin >> w[i];
        sumw += w[i];
    }
    for(int i = 1; i <= n; i++) {
        w[i] /= sumw;
        for(int j = i; j <= n; j += i) w_over_divs[j] += w[i];
    }
    vector<ld> dp(n + 1, 0);
    for(int i = n; i >= 1; i--) {
        vector<ld> cur_probs; cur_probs.pb(0); cur_probs.pb(w_over_divs[i]);
        for(int j = 2; i * j <= n; j++) {
            ld cur_prob = w_over_divs[j * i];
            for(int k = 1; k * k <= j; k++) {
                if(j % k == 0) {
                    cur_prob -= cur_probs[k];
                    if(j / k != k) cur_prob -= cur_probs[j / k];
                }
            }
            cur_probs.pb(cur_prob);
        }
        ld val = 1;
        for(int j = 2; j < len(cur_probs); j++) val += dp[i * j] * cur_probs[j];
        dp[i] = val / (1.0 - w_over_divs[i]);
    }
    cout << fixed << setprecision(21) << dp[1] - 1 << '\n'; //token 'taken' on pos1 shouldn't count
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;

//    cin >> t;

    while (t--) solve();

}

/*
KIVI
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3780kb

input:

3
1 1 1

output:

-nan

result:

wrong output format Expected double, but "-nan" found