QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#366945#8511. Greek Casinohos_lyricWA 1ms4072kbC++142.5kb2024-03-25 14:44:552024-03-25 14:44:56

Judging History

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

  • [2024-03-25 14:44:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4072kb
  • [2024-03-25 14:44:55]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


using Double = double;

int N;
vector<int> W;

int main() {
  for (; ~scanf("%d", &N); ) {
    W.resize(N + 1);
    for (int i = 1; i <= N; ++i) {
      scanf("%d", &W[i]);
    }
    
    vector<int> lpf(N + 1), primes;
    for (int p = 2; p <= N; ++p) lpf[p] = p;
    for (int p = 2; p <= N; ++p) if (lpf[p] == p) {
      primes.push_back(p);
      for (int n = p; n <= N; n += p) chmin(lpf[n], p);
    }
    
    Int sumW = 0;
    for (int i = 1; i <= N; ++i) {
      sumW += W[i];
    }
    // multiples of i
    vector<vector<Int>> wss(N + 1);
    for (int i = 1; i <= N; ++i) {
      auto &ws = wss[i];
      const int n = N / i;
      ws.assign(n + 1, 0);
      for (int j = 1; j <= n; ++j) ws[j] = W[i * j];
      for (const int p : primes) {
        if (p > n) break;
        for (int j = 1; p * j <= n; ++j) ws[j * p] += ws[j];
      }
    }
// cerr<<"wss = "<<wss<<endl;
    
    vector<Double> dp(N + 1);
    for (int u = N; u >= 1; --u) {
      // Pr[u -> v] = \sum[v/u | e | v] P[e]
      Double &f = dp[u] = 0.0;
      for (int i = 2; u * i <= N; ++i) f += wss[i][u] * dp[u * i];
      f /= sumW;
      f += 1.0;
      f /= (1 - wss[1][u] / (Double)sumW);
    }
    const Double ans = dp[1] - 1.0;
    printf("%.12f\n", ans);
  }
  return 0;
}

詳細信息

Test #1:

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

input:

3
1 1 1

output:

3.500000000000

result:

ok found '3.500000000', expected '3.500000000', error '0.000000000'

Test #2:

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

input:

3
1 1 2

output:

3.666666666667

result:

ok found '3.666666667', expected '3.666666667', error '0.000000000'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3932kb

input:

1337
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1.024263961543

result:

wrong answer 1st numbers differ - expected: '1.0183368', found: '1.0242640', error = '0.0058204'