Submission #529562

# Submission time Handle Problem Language Result Execution time Memory
529562 2022-02-23T07:28:17 Z Vimmer Magneti (COCI21_magneti) C++14
20 / 110
1000 ms 692 KB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")

#define F first
#define S second
#define PB push_back
#define M ll(1e9 + 7)
#define sz(x) (ll)x.size()
#define N 100005
#define pri(x) cout << x << endl
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

using namespace std;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;


int mlt(int x, int y)
{
    return 1ll * x * y % M;
}

int sm(int x, int y)
{
    x += y;

    if (x >= M)
        x -= M;

    return x;
}

int fact[N];

int binpow(int a, int b)
{
    if (b == 0)
        return 1;

    int s = binpow(a, b >> 1);

    s = mlt(s, s);

    if (b & 1)
        s = mlt(s, a);

    return s;
}

int C(int n, int k)
{
    return mlt(fact[n], binpow(mlt(fact[k], fact[n - k]), M - 2));
}

int ans, n, l;

void calc(vector <int> &r)
{
    int len = 1;

    for (int i = 1; i < n; i++)
    {
        int mx = max(r[i], r[i - 1]);

        len += mx;
    }

    if (l >= len)
        ans = sm(ans, C(l - len + n, n));
}

int main()
{
    istream::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//    freopen("1.in", "r", stdin);

    fact[0] = 1;

    for (int i = 1; i < N; i++)
        fact[i] = mlt(fact[i - 1], i);

    cin >> n >> l;

    vector <int> r(n);

    for (int i = 0; i < n; i++)
        cin >> r[i];

    int i = 0;

    while (i < fact[n])
    {
        i++;

        calc(r);

        next_permutation(all(r));
    }

    pri(ans);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 954 ms 692 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 961 ms 688 KB Output is correct
4 Correct 1 ms 660 KB Output is correct
5 Correct 53 ms 692 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 57 ms 688 KB Output is correct
8 Correct 53 ms 692 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 588 KB Time limit exceeded
2 Halted 0 ms 0 KB -