QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#363348 | #8511. Greek Casino | Days_of_Future_Past# | Compile Error | / | / | C++14 | 2.2kb | 2024-03-23 21:18:56 | 2024-03-23 21:18:56 |
Judging History
answer
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
typedef long long LL;
#define all(x) ((x).begin()), ((x).end())
#define pb push_back
typedef double D;
const int N = 100011;
bool isp[N];
int a[N], mnp[N], p[N];
D dp[N];
vector<int> fps[N], fs[N];
int sumf[N];
int main() {
int n;
scanf("%d", &n);
//n = 100000;
int np = 0;
fill(isp + 2, isp + n + 1, true);
p[0] = inf;
for(int i = 2; i <= n; i++) {
if(isp[i]) {
p[++np] = i;
mnp[i] = np;
}
for(int j = 1; j <= np && i * p[j] <= n && i % p[j - 1]; j++) {
isp[p[j] * i] = false;
mnp[p[j] * i] = j;
}
}
int tot = 0;
for(int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
//a[i] = 1;
tot += a[i];
}
for(int i = 1; i <= n; i++) {
int x = i;
while(x != 1) {
int id = mnp[x];
while(x != 1 && mnp[x] == id) {
x /= p[mnp[x]];
}
fps[i].pb(id);
}
for(int msk = 0; msk < (1 << fps[i].size()); msk++) {
int t = 1;
for(int j = 0; j < (int)fps[i].size(); j++) {
if((msk >> j) & 1) {
t *= p[fps[i][j]];
}
}
fs[i].pb(t);
}
}
for(int i = 1; i <= n; i++) {
for(int j = i; j <= n; j += i) {
sumf[j] += a[i];
}
}
for(int i = n; i >= 1; i--) {
dp[i] = 0;
double d = 0;
for(int j = i + i; j <= n; j += i) {
int sum = 0;
for(int msk = 0; msk < (1 << fps[j].size()); msk++) {
sum += (__builtin_popcount(msk) % 2 ? -1 : 1) * sumf[j / fs[j][msk]];
}
d += sum / (double)tot * dp[j];
}
//dp[i] = 1 + (sumf[i] / tot) * dp[i] + d
//(1 - sumf[i] / tot) * dp[i] = (1 + d)
dp[i] = (1 + d) * tot / (tot - sumf[i]);
// printf("dp[%d] = %lf\n", i, dp[i]);
}
printf("%.12f\n", dp[1] - 1);
}
Details
answer.code: In function ‘int main()’: answer.code:18:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ answer.code:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | scanf("%d", &a[i]); | ~~~~~^~~~~~~~~~~~~ In file included from /usr/include/c++/13/string:43, from /usr/include/c++/13/bitset:52, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52, from answer.code:3: /usr/include/c++/13/bits/allocator.h: In destructor ‘std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()’: /usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]’: target specific option mismatch 184 | ~allocator() _GLIBCXX_NOTHROW { } | ^ In file included from /usr/include/c++/13/vector:66, from /usr/include/c++/13/queue:63, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:157: /usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here 133 | struct _Vector_impl | ^~~~~~~~~~~~