Submission #529562

#TimeUsernameProblemLanguageResultExecution timeMemory
529562VimmerMagneti (COCI21_magneti)C++14
20 / 110
1079 ms692 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...