QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#110976 | #6565. Game Show Elimination | heno239 | AC ✓ | 2540ms | 30720kb | C++17 | 12.2kb | 2023-06-05 03:30:27 | 2023-06-05 03:30:30 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
//ll mod = 1;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000007;
const int mod17 = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
using ld = long double;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);
template<typename T>
void chmin(T& a, T b) {
a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
a = max(a, b);
}
template<typename T>
vector<T> vmerge(vector<T>& a, vector<T>& b) {
vector<T> res;
int ida = 0, idb = 0;
while (ida < a.size() || idb < b.size()) {
if (idb == b.size()) {
res.push_back(a[ida]); ida++;
}
else if (ida == a.size()) {
res.push_back(b[idb]); idb++;
}
else {
if (a[ida] < b[idb]) {
res.push_back(a[ida]); ida++;
}
else {
res.push_back(b[idb]); idb++;
}
}
}
return res;
}
template<typename T>
void cinarray(vector<T>& v) {
rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
rep(i, v.size()) {
if (i > 0)cout << " "; cout << v[i];
}
cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
//if (x == 0)return 0;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
//mod should be <2^31
struct modint {
int n;
modint() :n(0) { ; }
modint(ll m) {
if (m < 0 || mod <= m) {
m %= mod; if (m < 0)m += mod;
}
n = m;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
ll gcd(ll a, ll b) {
a = abs(a); b = abs(b);
if (a < b)swap(a, b);
while (b) {
ll r = a % b; a = b; b = r;
}
return a;
}
template<typename T>
void addv(vector<T>& v, int loc, T val) {
if (loc >= v.size())v.resize(loc + 1, 0);
v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
fill(isp + 2, isp + mn, true);
for (int i = 2; i < mn; i++) {
if (!isp[i])continue;
ps.push_back(i);
for (int j = 2 * i; j < mn; j += i) {
isp[j] = false;
}
}
}*/
//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
if (res == st.begin())return st.end();
res--; return res;
}
//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
a = a + b; return a;
}
mP operator-(mP a, mP b) {
return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
a = a - b; return a;
}
LP operator+(LP a, LP b) {
return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
a = a + b; return a;
}
LP operator-(LP a, LP b) {
return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
a = a - b; return a;
}
mt19937 mt(time(0));
const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
//int dx[4] = { 1,0,-1,0 };
//int dy[4] = { 0,1,0,-1 };
//-----------------------------------------
using poly = vector<ld>;
poly operator*(poly a, poly b) {
poly res;
if (a.empty() || b.empty())return res;
res.resize(a.size() + b.size() - 1);
rep(i, a.size())rep(j, b.size()) {
res[i + j] += a[i] * b[j];
}
return res;
}
int k;
ld coef[1 << 21][21];
bool chked[1 << 21];
ld calc_c(int i, int cc) {
//cout << "?? " << i << "\n";
if (chked[i]) {
return coef[i][cc];
}
chked[i] = true;
vector<int> vs;
rep(j, 2*k+1)if (i & (1 << j))vs.push_back(j);
assert(vs.size() > 1);
ld bb = 1;
rep(i, vs.size())bb *= k;
rep(x, vs.size()) {
rep(y, vs.size()) {
if (x == y)continue;
for (int l = vs[y] - k; l < vs[y]; l++) {
poly p = { 1 };
rep(i, vs.size()) {
if (i == y)continue;
if (i == x) {
int le = vs[i] - k;
int ri = vs[i];
if (l + 1 <= le) {
p.clear();
}
else if (ri <= l) {
poly cur = { (ld)k };
p = p * cur;
}
else {
poly cur = { (ld)-le,(ld)1 };
p = p * cur;
}
}
else {
int le = vs[i] - k; int ri = vs[i];
if (l + 1 <= le) {
poly cur = { (ld)k };
p = p * cur;
}
else if (ri <= l) {
p.clear();
}
else {
poly cur = { (ld)ri,(ld)-1 };
p = p * cur;
}
}
}
//coutarray(p);
ld pl = 1;
ld plp = 1;
ld sum = 0;
rep(i, p.size()) {
pl *= l;
plp *= l + 1;
ld coef = p[i] / (ld)(i + 1);
sum += coef * (plp - pl);
}
coef[i][vs[y]] += sum;
}
}
}
rep(j, vs.size()) {
coef[i][vs[j]] /= bb;
}
return coef[i][cc];
}
const ld z = (1e-15);
void solve() {
map<vector<int>, ld> mp;
int n; cin >> n >> k;
rep(i, (1 << (k + 1))) {
if (i % 2 == 0)continue;
}
vector<int> cur;
for (int i = max(0, n - 1 - k); i < n; i++) {
cur.push_back(i);
}
mp[cur] = 1;
vector<ld> ans(n);
vector<int> nv;
rep(_, n - 2) {
//cout << "hello " << _ << "\n";
int cval = n - _;
map<vector<int>, ld> nmp;
for (auto p : mp) {
vector<int> v = p.first;
ld val = p.second;
//cout << val << " "; coutarray(v);
if (val < z)continue;
//cout << "? " << _ << "\n";
assert(v.size() >= 2);
assert(v[v.size() - 1] - v[v.size() - 2] <= k);
//coutarray(v);
int r = n - _ - v.size();
int ss = 0;
rep(i, v.size()) {
ss |= (1 << (v.back() - v[i]));
}
bool curb = false;
if (v.back() - v[v.size() - 2] == k)curb = true;
rep(i, v.size()) {
int loc = v.back() - v[i];
//cout << "!? " << ss << " " << loc << "\n";
ld nval = val * calc_c(ss, loc);
ans[v[i]] += nval * cval;
vector<int> nv;
if (i + 1 == v.size()) {
nv = v;
nv.erase(nv.begin() + i);
if (nv.size() == 1) {
int las = nv.back();
for (int j = las - 2 * k+1; j <= las - k; j++) {
if (j >= 0)nv.push_back(j);
}
}
else {
int cr = v[v.size() - 2];
int cl = nv[nv.size() - 2];
Rep(j, cl, cr) {
if(j-k+1>=0)nv.push_back(j - k + 1);
}
}
sort(all(nv));
}
else if (i + 2 == v.size()) {
nv = v;
nv.erase(nv.begin() + i);
if (nv.size() == 1) {
for (int j = v[i] - 2 * k + 1; j <= v[i] - k; j++) {
if (j >= 0)nv.push_back(j);
}
}
else {
int cr = v[v.size() - 2];
int cl = nv[nv.size() - 2];
Rep(j, cl, cr) {
if (j - k + 1 >= 0)nv.push_back(j - k + 1);
}
}
sort(all(nv));
}
else {
nv = v;
nv.erase(nv.begin() + i);
}
if (nv.back() - nv[nv.size() - 2] >= k) {
if (!curb) {
ans[nv.back()] += nval;
}
nv.back() = nv[nv.size() - 2] + k;
}
nmp[nv] += nval;
}
}
swap(mp, nmp);
//cout << mp.size() << "\n";
}
//cout << "hello\n";
for (auto p : mp) {
vector<int> v = p.first;
int ss = 1;
ss |= 1 << (v[1] - v[0]);
ld c0 = calc_c(ss, v[1] - v[0]);
ld c1 = 1 - c0;
ans[v[0]] += 2 * c0 * p.second + c1 * p.second;
if (v[1] - v[0] < k) {
ans[v[1]] += c0 * p.second + 2 * c1 * p.second;
}
}
rep(i, n)cout << ans[i] << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
//init_f();
//init();
//while(true)
//expr();
//int t; cin >> t; rep(i, t)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 13652kb
input:
3 2
output:
2.1093750000 2.6250000000 1.2656250000
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 2540ms
memory: 30720kb
input:
1000 10
output:
2.9272933165 3.5373161568 4.2811822032 5.1312206600 6.0539327788 7.0191885096 8.0057023988 9.0012910300 10.0001652073 10.9999999996 11.9999999996 12.9999999996 13.9999999995 14.9999999995 15.9999999995 16.9999999994 17.9999999994 18.9999999994 19.9999999993 20.9999999993 21.9999999993 22.9999999992 ...
result:
ok 1000 numbers
Test #3:
score: 0
Accepted
time: 217ms
memory: 16608kb
input:
300 8
output:
2.7512630513 3.3900737270 4.1750068651 5.0660215194 6.0201465578 7.0045578589 8.0005725930 9.0000000000 10.0000000000 11.0000000000 12.0000000000 12.9999999999 13.9999999999 14.9999999999 15.9999999999 16.9999999999 17.9999999999 18.9999999999 19.9999999999 20.9999999999 21.9999999999 22.9999999999 ...
result:
ok 300 numbers
Test #4:
score: 0
Accepted
time: 11ms
memory: 12968kb
input:
1000 3
output:
2.2302561681 3.0347656711 4.0000000000 5.0000000000 6.0000000000 7.0000000000 8.0000000000 9.0000000000 10.0000000000 11.0000000000 12.0000000000 13.0000000000 14.0000000000 15.0000000000 16.0000000000 17.0000000000 18.0000000000 19.0000000000 20.0000000000 21.0000000000 22.0000000000 23.0000000000 ...
result:
ok 1000 numbers
Test #5:
score: 0
Accepted
time: 3ms
memory: 13452kb
input:
7 10
output:
2.9815864384 3.4936049601 3.9653422649 4.3196770586 4.5087248562 4.4988808477 4.2321835741
result:
ok 7 numbers
Test #6:
score: 0
Accepted
time: 911ms
memory: 20404kb
input:
993 9
output:
2.8411212285 3.4643592446 4.2273243674 5.0969425981 6.0352816657 7.0105742427 8.0023873941 9.0003025183 9.9999999999 10.9999999999 11.9999999999 12.9999999998 13.9999999998 14.9999999998 15.9999999998 16.9999999998 17.9999999998 18.9999999998 19.9999999998 20.9999999998 21.9999999997 22.9999999997 2...
result:
ok 993 numbers