Submission #65486892


Source Code Expand

/*
    Template Version: 1.0.0 - 20220620
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define ALL(a) a.begin(), a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define TRAV(x, a) for (auto &x : a)

using namespace std;
using ll = long long; using ld = double; 
using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>;
using cd = complex<ld>; using vcd = vector<cd>;

using vi = vector<int>; using vl = vector<ll>;
using vd = vector<ld>; using vs = vector<string>;
using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; // vector<pair>

template<class T> using min_pq = priority_queue<T, vector<T>, greater<T> >;
template<class T> inline int ckmin(T& a, const T& val) { return val < a ? a = val, 1 : 0; }
template<class T> inline int ckmax(T& a, const T& val) { return a < val ? a = val, 1 : 0; }
template<class T> void remDup(vector<T>& v) { sort(ALL(v)); v.erase(unique(ALL(v)), end(v)); }

constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x)) 
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }

ll ceilDiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
ll floorDiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } // divide a by b rounded down
void setPrec(int x) { cout << fixed << setprecision(x); }

// TO_STRING
#define ts to_string
string ts(char c) { return string(1, c); }
string ts(const char* s) { return (string) s; }
string ts(string s) { return s; }
string ts(bool b) { return (b ? "true" : "false"); }

template<class T> using V = vector<T>;
template<class T> string ts(complex<T> c);
string ts(V<bool> v);
template<size_t sz> string ts(bitset<sz> b);
template<class T> string ts(T v);
template<class T, class U> string ts(pair<T,U> p);
template<class ...U> string ts(tuple<U...> u);

template<class T> string ts(complex<T> c) { stringstream ss; ss << c; return ss.str(); }
string ts(V<bool> v) {string res = "{"; FOR(i,0,SZ(v)-1) res += char('0'+v[i]); res += "}"; return res; }
template<size_t sz> string ts(bitset<sz> b) { string res = ""; FOR(i,0,SZ(b)-1) res += char('0'+b[i]); return res; }
template<class T> string ts(T v) { // containers with begin(), end()
    bool fst = 1; string res = "";
    for (const auto& x: v) { if (!fst) res += " "; fst = 0; res += ts(x); }
    return res;
}
template<class T, class U> string ts(pair<T,U> p) { return "(" + ts(p.FI) + ", " + ts(p.SE) + ")"; }
template<size_t i, class T> string print_tuple_utils(const T& tup) { if constexpr(i == tuple_size<T>::value) return ")"; else return (i ? ", " : "(") + ts(get<i>(tup)) + print_tuple_utils<i + 1, T>(tup); }
template<class ...U> string ts(tuple<U...> u) { return print_tuple_utils<0, tuple<U...>>(u); }

// OUTPUT
template<class T> void pr(T x) { cout << ts(x); }
template<class T, class ...U> void pr(const T& t, const U&... u) { pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces
template<class T, class ...U> void ps(const T& t, const U&... u) { pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class T, class ...U> void DBG(const T& t, const U&... u) { cerr << ts(t); if (sizeof...(u)) cerr << ", "; DBG(u...); }

#ifdef LOCAL_DEBUG
#define CONCAT(x, y) x##y
#define with_level setw(__db_level * 2) << setfill(' ') << "" << setw(0)
#define dbg(...) cerr << with_level << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#define chk(...) if (!(__VA_ARGS__)) cerr << setw(__db_level * 2) << setfill(' ') << "" << setw(0) << "Line(" << __LINE__ << ") -> function(" << __FUNCTION__  << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
#define db_block() debug_block CONCAT(dbbl, __LINE__)
int __db_level = 0;
struct debug_block {
    debug_block() { cerr << with_level << "{" << endl; ++__db_level; }
    ~debug_block() { --__db_level; cerr << with_level << "}" << endl; }
};
#else
#define dbg(...) 0
#define chk(...) 0
#define db_block() 0
#endif

const ld PI = acos(-1.0);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const ld EPS = 1e-9;
const ll MODBASE = 1000000007LL;
const int INF = 0x3f3f3f3f;

const int MAXN = 200001;
const int MAXM = 31;
const int MAXK = 31;
const int MAXT = 31;

int N, T, M, K;
ld dp[MAXT][MAXK];
vector<vi> partitions;

void dfs(int m, int s, vi &cur) {
    if (s == M) {
        if (SZ(cur) <= N) {
            partitions.push_back(cur);
            dbg(cur);
        }
    } else if (m >= 1) {
        int Max = (M - s) / m;
        FOR(i,0,Max) {
            dfs(m-1, s+m*i, cur);
            cur.push_back(m);
        }
        FOR(i,0,Max) cur.pop_back();
    }
}

ld solve(int turn, int pressed) {
    if (pressed >= K) return 1;
    if (turn == T) return 0;
    if (dp[turn][pressed] > -EPS) return dp[turn][pressed];
    ld &res = dp[turn][pressed];
    res = 0;

    // for each strategy
    TRAV(partition, partitions) {
        ld p = solve(turn+1, pressed) * (N - SZ(partition)) / N;

        TRAV(sz, partition) {
            p += solve(turn+1, pressed + sz) / N;
        }

        ckmax(res, p);
    }

    return res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> N >> T >> M >> K;

    // separate M into partition sizes, sorted in non-increasing order
    // each will be a strategy to press buttons
    vi cur;
    dfs(M, 0, cur);

    MS(dp, -1);
    setPrec(9);
    cout << solve(0, 0);
    return 0;
}

Submission Info

Submission Time
Task F - Lost and Pound
User farmerboy
Language C++ 20 (gcc 12.2)
Score 550
Code Size 5989 Byte
Status AC
Exec Time 182 ms
Memory 4280 KiB

Compile Error

Main.cpp: In function ‘void dfs(int, int, vi&)’:
Main.cpp:91:18: warning: statement has no effect [-Wunused-value]
   91 | #define dbg(...) 0
      |                  ^
Main.cpp:115:13: note: in expansion of macro ‘dbg’
  115 |             dbg(cur);
      |             ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 550 / 550
Status
AC × 3
AC × 54
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt, random_45.txt, random_46.txt, random_47.txt, random_48.txt, random_49.txt, random_50.txt, random_51.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 1 ms 3840 KiB
random_02.txt AC 1 ms 3852 KiB
random_03.txt AC 36 ms 4096 KiB
random_04.txt AC 64 ms 4116 KiB
random_05.txt AC 76 ms 4052 KiB
random_06.txt AC 1 ms 3800 KiB
random_07.txt AC 2 ms 3752 KiB
random_08.txt AC 7 ms 3868 KiB
random_09.txt AC 1 ms 3656 KiB
random_10.txt AC 13 ms 3856 KiB
random_11.txt AC 1 ms 3808 KiB
random_12.txt AC 2 ms 3952 KiB
random_13.txt AC 3 ms 3888 KiB
random_14.txt AC 1 ms 3912 KiB
random_15.txt AC 1 ms 3796 KiB
random_16.txt AC 2 ms 3892 KiB
random_17.txt AC 1 ms 3844 KiB
random_18.txt AC 3 ms 3828 KiB
random_19.txt AC 1 ms 3700 KiB
random_20.txt AC 1 ms 3864 KiB
random_21.txt AC 1 ms 3804 KiB
random_22.txt AC 1 ms 3808 KiB
random_23.txt AC 1 ms 3860 KiB
random_24.txt AC 8 ms 4012 KiB
random_25.txt AC 9 ms 3688 KiB
random_26.txt AC 1 ms 3832 KiB
random_27.txt AC 2 ms 3960 KiB
random_28.txt AC 1 ms 3868 KiB
random_29.txt AC 2 ms 3880 KiB
random_30.txt AC 1 ms 3844 KiB
random_31.txt AC 4 ms 3876 KiB
random_32.txt AC 1 ms 3788 KiB
random_33.txt AC 182 ms 4124 KiB
random_34.txt AC 1 ms 3688 KiB
random_35.txt AC 2 ms 4116 KiB
random_36.txt AC 1 ms 3688 KiB
random_37.txt AC 1 ms 3720 KiB
random_38.txt AC 1 ms 3848 KiB
random_39.txt AC 1 ms 3840 KiB
random_40.txt AC 1 ms 3872 KiB
random_41.txt AC 5 ms 4280 KiB
random_42.txt AC 1 ms 3788 KiB
random_43.txt AC 1 ms 4156 KiB
random_44.txt AC 1 ms 3832 KiB
random_45.txt AC 1 ms 3840 KiB
random_46.txt AC 1 ms 3780 KiB
random_47.txt AC 1 ms 3704 KiB
random_48.txt AC 1 ms 3768 KiB
random_49.txt AC 22 ms 3872 KiB
random_50.txt AC 1 ms 3792 KiB
random_51.txt AC 1 ms 4008 KiB
sample_01.txt AC 1 ms 3836 KiB
sample_02.txt AC 1 ms 3792 KiB
sample_03.txt AC 1 ms 3644 KiB