結果

問題 No.2389 Cheating Code Golf
ユーザー shogo314shogo314
提出日時 2023-07-21 22:50:39
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 835 ms / 2,000 ms
コード長 5,779 bytes
コンパイル時間 3,367 ms
コンパイル使用メモリ 259,468 KB
実行使用メモリ 16,968 KB
最終ジャッジ日時 2023-10-21 22:54:42
合計ジャッジ時間 7,942 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 139 ms
7,128 KB
testcase_03 AC 835 ms
16,968 KB
testcase_04 AC 813 ms
16,968 KB
testcase_05 AC 12 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 20 ms
4,404 KB
testcase_08 AC 223 ms
8,004 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 22 ms
4,560 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 140 ms
7,128 KB
testcase_14 AC 37 ms
4,920 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 151 ms
7,204 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 26 ms
4,560 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 11 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 17 ms
4,360 KB
testcase_25 AC 11 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 29 ms
4,804 KB
testcase_28 AC 14 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 117 ms
6,564 KB
testcase_31 AC 7 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 45 ms
5,124 KB
testcase_35 AC 10 ms
4,348 KB
testcase_36 AC 114 ms
6,564 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 288 ms
9,604 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 4 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 240 ms
8,644 KB
testcase_46 AC 91 ms
6,084 KB
testcase_47 AC 1 ms
4,348 KB
testcase_48 AC 17 ms
4,380 KB
testcase_49 AC 37 ms
4,920 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 24 ms
4,560 KB
testcase_52 AC 10 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

// #include <atcoder/all>

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;
// using namespace atcoder;

using ll = long long;
using str = string;
using pl = pair<ll, ll>;
template <typename T>
using ml = map<ll, T>;
using mll = ml<ll>;
using sl = set<ll>;
using dbl = double;
using pd = pair<dbl, dbl>;
template <typename T>
using vec = vector<T>;
template <typename T>
using vv = vec<vec<T>>;
template <typename T1, typename T2>
using vp = vec<pair<T1, T2>>;
using vl = vec<ll>;
using vvl = vec<vl>;
using vs = vec<str>;
using vc = vec<char>;
using vpl = vec<pl>;
using vd = vec<dbl>;
using vpd = vec<pd>;
using tl3 = tuple<ll, ll, ll>;

using ld = long double;

const double INF = std::numeric_limits<double>::infinity();

#define LL(x) \
    ll x;     \
    cin >> x;
#define STR(s) \
    str s;     \
    cin >> s;
#define VL(a, n) \
    vl a(n);     \
    cin >> a;

#define all(obj) (obj).begin(), (obj).end()

#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repds(i, a, n) for (ll i = (n - 1); i >= (a); i--)
#define repd(i, n) repds(i, 0, n)
#define rrepd(i, n) repds(i, 1, n + 1)
#define rep2(i, j, x, y) rep(i, x) rep(j, y)

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

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << " " << p.second;
    return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i + 1 != (int)v.size() ? " " : "");
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &s) {
    os << vec<T>(s.begin(), s.end());
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &in : v) is >> in;
    return is;
}
void print() { cout << '\n'; }
template <typename T>
void print(const T &t) {
    cout << t << '\n';
}
template <typename Head, typename... Tail>
void print(const Head &head, const Tail &...tail) {
    cout << head << ' ';
    print(tail...);
}
void print_accurate(dbl x) {
    cout << scientific << setprecision(15) << x << '\n';
}
void print_accurate(ld x) {
    cout << scientific << setprecision(15) << x << '\n';
}

void repr_(const ll &x) { cerr << x; }
void repr_(const int &x) { cerr << x; }
void repr_(const dbl &x) { cerr << x; }
void repr_(const str &x) { cerr << x; }
void repr_(const char &x) { cerr << x; }
void repr_(const char *x) { cerr << x; }
template <typename T1, typename T2>
void repr_(const pair<T1, T2> &p);
template <typename T1, typename T2>
void repr_(const map<T1, T2> &m);
template <typename T>
void repr_(const vec<T> &v);
template <typename T>
void repr_(const set<T> &s);
template <typename T1, typename T2>
void repr_(const pair<T1, T2> &p) {
    cerr << '(';
    repr_(p.first);
    cerr << ", ";
    repr_(p.second);
    cerr << ')';
}
template <typename T>
void repr_(const vec<T> &v) {
    cerr << '[';
    for (int i = 0; i < (int)v.size(); i++) {
        repr_(v[i]);
        if (i + 1 != (int)v.size()) cerr << ", ";
    }
    cerr << ']';
}
template <typename T>
void repr_(const set<T> &s) {
    cerr << '{';
    vec<T> v = vec<T>(all(s));
    for (int i = 0; i < (int)v.size(); i++) {
        repr_(v[i]);
        if (i + 1 != (int)v.size()) cerr << ", ";
    }
    cerr << '}';
}
template <typename T1, typename T2>
void repr_(const map<T1, T2> &m) {
    cerr << '{';
    vp<T1, T2> v = vp<T1, T2>(all(m));
    for (int i = 0; i < (int)v.size(); i++) {
        repr_(v[i].first);
        cerr << ": ";
        repr_(v[i].second);
        if (i + 1 != (int)v.size()) cerr << ", ";
    }
    cerr << '}';
}
template <typename Head, typename... Tail>
void repr_(const Head &head, const Tail &...tail) {
    repr_(head);
    repr_(' ');
    repr_(tail...);
}
template <typename T>
void repr(const T &t) {
    repr_(t);
    cerr << '\n';
}
template <typename Head, typename... Tail>
void repr(const Head &head, const Tail &...tail) {
    repr_(head);
    repr_(' ');
    repr(tail...);
}

ll N, M;
vec<pair<ll, pl>> ABP;
map<pl, ld> d;
// ll cnt = 0;

#define max(x, y) ((x) > (y) ? (x) : (y))

ld query(ll solved, ll m) {
    // if (cnt++ > 10) {
    //     exit(0);
    // }
    // print("query", solved, m);
    if (d.find(pl(solved, m)) != d.end()) {
        return d[pl(solved, m)];
    }
    ld temp = 0;
    rep(i, N) {
        if ((solved) & (1 << i)) continue;
        ll x = solved | (1 << i);
        // print(solved, m, i, (ld)1 / ABP.at(i).first + query(x, m));
        chmax(temp, (ld)1 / ABP.at(i).first + query(x, m));
        if (m > 0) {
            // print(solved, m, i, (ld)1 / ABP.at(i).second.second * ((ld)1 / ABP.at(i).second.first + query(x, m)) + (1 - (ld)1 / ABP.at(i).second.second) * (query(solved, m - 1)));
            chmax(temp, (ld)1 / ABP.at(i).second.second * ((ld)1 / ABP.at(i).second.first + query(x, m)) + (1 - (ld)1 / ABP.at(i).second.second) * (query(solved, m - 1)));
        }
    }
    d[pl(solved, m)] = temp;
    // print(solved, m, temp);
    return temp;
}

void solve() {
    cin >> N >> M;
    ABP = vec<pair<ll, pl>>(N);
    cin >> ABP;
    print_accurate(query(0, M));
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}
0