답안 #526978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526978 2022-02-16T18:46:04 Z bibabas Magneti (COCI21_magneti) C++14
60 / 110
40 ms 20228 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC optimize("inline")
//#pragma GCC optimize("-fgcse")
//#pragma GCC optimize("-fgcse-lm")
//#pragma GCC optimize("-fipa-sra")
//#pragma GCC optimize("-ftree-pre")
//#pragma GCC optimize("-ftree-vrp")
//#pragma GCC optimize("-fpeephole2")
//#pragma GCC optimize("-ffast-math")
//#pragma GCC optimize("-fsched-spec")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-falign-jumps")
//#pragma GCC optimize("-falign-loops")
//#pragma GCC optimize("-falign-labels")
//#pragma GCC optimize("-fdevirtualize")
//#pragma GCC optimize("-fcaller-saves")
//#pragma GCC optimize("-fcrossjumping")
//#pragma GCC optimize("-fthread-jumps")
//#pragma GCC optimize("-funroll-loops")
//#pragma GCC optimize("-fwhole-program")
//#pragma GCC optimize("-freorder-blocks")
//#pragma GCC optimize("-fschedule-insns")
//#pragma GCC optimize("inline-functions")
//#pragma GCC optimize("-ftree-tail-merge")
//#pragma GCC optimize("-fschedule-insns2")
//#pragma GCC optimize("-fstrict-aliasing")
//#pragma GCC optimize("-fstrict-overflow")
//#pragma GCC optimize("-falign-functions")
//#pragma GCC optimize("-fcse-skip-blocks")
//#pragma GCC optimize("-fcse-follow-jumps")
//#pragma GCC optimize("-fsched-llerblock")
//#pragma GCC optimize("-fpartial-inlining")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("-freorder-functions")
//#pragma GCC optimize("-findirect-inlining")
//#pragma GCC optimize("-fhoist-adjacent-loads")
//#pragma GCC optimize("-frerun-cse-after-loop")
//#pragma GCC optimize("-inline-small-functions")
//#pragma GCC optimize("-finline-small-functions")
//#pragma GCC optimize("-ftree-switch-conversion")
//#pragma GCC optimize("-foptimize-sibling-calls")
//#pragma GCC optimize("-fexpensive-optimizations")
//#pragma GCC optimize("-funsafe-loop-optimizations")
//#pragma GCC optimize("inline-functions-called-once")
//#pragma GCC optimize("-fdelete-null-poller-checks")
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned ll
#define vi vector<ll>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ld long double
#define pii pair<ll, ll>
#define mt make_tuple
#define mn(a, b) a = min(a, b)
#define mx(a, b) a = max(a, b)
#define base complex<ld>
#define START_DEPTH 18

using namespace std;
const ll inf = (ll)1e18;
const ld eps = (ld)1e-12;
const ll mod = (ll)1e9 + 7;
const ll mod2 = (ll)1e9 + 9;
const ll MAXN = (ll)42 + 10;
const ll MAXC = (ll)1e5 + 10;
const ll MAXLOG = (ll)20;
const ll asci = (ll)256;
const ll block = 316;
const ld PI = acos(-1LL);
const ll INF = 2e9;
const ld e = 2.7182818284;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//
//typedef tree<
//ll,
//null_type,
//less<ll>,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

// === Debug macro starts here ===
template<typename A, typename B>
string to_string(pair<A, B> p);

template<typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template<typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string) s);
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (ll i = 0; i < static_cast<ll>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template<typename A>
string to_string(A &v) {
    bool first = true;
    string res = "{";
    for (const auto &x: v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template<typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template<typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

string to_string(char c) {
    return string() + c;
}

template<typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " +
           to_string(get<3>(p)) + ")";
}

template<typename A, std::size_t N>
string to_string(A (&v)[N]) {
    bool first = true;
    string res = "{";
    for (ll i = 0; i < N; i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << "\n"; }

template<typename Head, typename... Tail>
void debug_out(Head &H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef DEBUG
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__);
#else
#define dbg(...);
#endif

// === Debug macro ends here ===

pii operator +(const pii &a, const pii &b) {
    return {a.first + b.first, a.second + b.second};
}

template <class T>
istream& operator >>(istream &in, vector<T> &arr){
    for (T &cnt : arr) {
        in >> cnt;
    }
    return in;
};

const ll MAXS = 10002;
ll dp[MAXN][MAXN][MAXS];
ll fact[MAXS];

ll fast_pow(ll x, ll y) {
    ll cnt = x;
    ll ans = 1;
    for (ll i = 0; 1 << i < y; ++i) {
        if (1 << i & y) ans *= cnt, ans %= mod;
        cnt *= cnt;
        cnt %= mod;
    }
    return ans;
}

ll C(ll n, ll k) {
    return fact[n] * fast_pow((fact[k] * fact[n - k]) % mod, mod - 2) % mod;
}

void solve() {
    fact[0] = 1;
    for (ll i = 1; i < MAXS; ++i) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    ll n, l; cin >> n >> l;
    vi r(n); cin >> r;
    for (ll &i : r) --i;
    sort(all(r));
    dp[1][0][0] = 1;
    for (ll i = 1; i < n; ++i) {
        for (ll cnt = 0; cnt < i; ++cnt) {
            for (ll s = 0; s < l; ++s) {
                if (!dp[i][cnt][s]) continue;
                dp[i + 1][cnt + 1][s] += 2 * dp[i][cnt][s];
                dp[i + 1][cnt + 1][s] %= mod;
                dp[i + 1][cnt][s + r[i]] += 2 * dp[i][cnt][s];
                dp[i + 1][cnt][s + r[i]] %= mod;
                if (cnt) {
                    dp[i + 1][cnt - 1][s + 2 * r[i]] += cnt * dp[i][cnt][s];
                    dp[i + 1][cnt - 1][s + 2 * r[i]] %= mod;
                    dp[i + 1][cnt][s + r[i]] += 2 * cnt * dp[i][cnt][s];
                    dp[i + 1][cnt][s + r[i]] %= mod;
                    dp[i + 1][cnt + 1][s] += cnt * dp[i][cnt][s];
                    dp[i + 1][cnt + 1][s] %= mod;
                }
            }
        }
    }
    dbg(dp);
    ll ans = 0;
    for (ll s = 0; s <= l; ++s) {
        if (l - s >= n) ans += dp[n][0][s] * C(l - s, n);
        ans %= mod;
    }
    cout << ans << "\n";
}

signed main() {
    srand(time(0LL));
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#endif
    cout.precision(30);
//#define TEST
#ifdef TEST
    ll t; cin >> t;
    while (t--)
#endif

    solve();

    return 0LL;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 5828 KB Output is correct
2 Correct 3 ms 5772 KB Output is correct
3 Correct 3 ms 716 KB Output is correct
4 Correct 2 ms 392 KB Output is correct
5 Correct 2 ms 1356 KB Output is correct
6 Correct 8 ms 2188 KB Output is correct
7 Correct 11 ms 1484 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 8 ms 2204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 972 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 3 ms 1100 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 1100 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 3 ms 1612 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2508 KB Output is correct
2 Correct 1 ms 1356 KB Output is correct
3 Correct 2 ms 2508 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 2 ms 2508 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 5828 KB Output is correct
2 Correct 3 ms 5772 KB Output is correct
3 Correct 3 ms 716 KB Output is correct
4 Correct 2 ms 392 KB Output is correct
5 Correct 2 ms 1356 KB Output is correct
6 Correct 8 ms 2188 KB Output is correct
7 Correct 11 ms 1484 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 8 ms 2204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 972 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 3 ms 1100 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 3 ms 1100 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 3 ms 1612 KB Output is correct
18 Correct 1 ms 716 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 2508 KB Output is correct
22 Correct 1 ms 1356 KB Output is correct
23 Correct 2 ms 2508 KB Output is correct
24 Correct 1 ms 1484 KB Output is correct
25 Correct 2 ms 2508 KB Output is correct
26 Correct 1 ms 1228 KB Output is correct
27 Correct 2 ms 2636 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 1100 KB Output is correct
30 Correct 1 ms 716 KB Output is correct
31 Correct 38 ms 16776 KB Output is correct
32 Correct 26 ms 12752 KB Output is correct
33 Correct 40 ms 17216 KB Output is correct
34 Correct 8 ms 3976 KB Output is correct
35 Correct 37 ms 16452 KB Output is correct
36 Correct 3 ms 1296 KB Output is correct
37 Correct 39 ms 17672 KB Output is correct
38 Correct 8 ms 6988 KB Output is correct
39 Incorrect 40 ms 20228 KB Output isn't correct
40 Halted 0 ms 0 KB -