Submission #863109

# Submission time Handle Problem Language Result Execution time Memory
863109 2023-10-19T15:30:17 Z Mizo_Compiler Magneti (COCI21_magneti) C++14
30 / 110
41 ms 17096 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define pb push_back
#define sz(x) int32_t(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define int long long
const int N = 51, M = 1e9+7, L = 4e4;
int n, l;
pair<int, int> r[N];
ll fact[L+52], ncr[L+1][N+1];

ll fp(ll b, ll p) {
	ll ret = 1;
	while (p) {
		if ((p & 1))ret = (ret * b) % M;
		b = (b * b) % M;
		p >>= 1;
	}
	return ret;
}

ll nCr(int a, int b) {
	if (a < 0 || b > a)return 0;
	return ncr[a][b];
}

signed main () {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> l;
	fact[0] = 1;
	for (ll i = 1; i <= L+50; i++) {
		fact[i] = (fact[i-1] * i) % M;
	}
	ncr[0][0] = 1;
	for (int i = 1; i <= L; i++) {
		for (int j = 0; j <= min(n, i); j++) {
			if (!j || j == i) {
				ncr[i][j] = 1;
				continue;
			}	
			ncr[i][j] = (ncr[i-1][j] + ncr[i-1][j-1]) % M;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> r[i].F;
		r[i].S = i;
	}
  	sort(r, r+n);
  	if (r[0].F == r[n-1].F) {
  	cout << (fact[n] * nCr(l - (n-1)*r[0].F + n - 1, n))%M << "\n";
      return 0;
    }
	if (n <= 10) {
		ll ans = 0;
		do {
			int len = 1;
			for (int i = 1; i < n; i++) {
				len += max(r[i].F, r[i-1].F);
			}
			ans = (ans + nCr(l - len + n, n)) % M;
		} while(next_permutation(r, r+n));
		cout << ans << "\n";
		return 0;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 16988 KB Output is correct
2 Correct 5 ms 17032 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 4 ms 17028 KB Output is correct
6 Correct 5 ms 17096 KB Output is correct
7 Correct 5 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 4 ms 16848 KB Output is correct
10 Correct 2 ms 16984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 16988 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 41 ms 17040 KB Output is correct
4 Correct 3 ms 16984 KB Output is correct
5 Correct 36 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 36 ms 17052 KB Output is correct
8 Correct 35 ms 17028 KB Output is correct
9 Correct 3 ms 16984 KB Output is correct
10 Correct 3 ms 16984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 16988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 16988 KB Output is correct
2 Correct 5 ms 17032 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 4 ms 17028 KB Output is correct
6 Correct 5 ms 17096 KB Output is correct
7 Correct 5 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 4 ms 16848 KB Output is correct
10 Correct 2 ms 16984 KB Output is correct
11 Correct 40 ms 16988 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 41 ms 17040 KB Output is correct
14 Correct 3 ms 16984 KB Output is correct
15 Correct 36 ms 16988 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 36 ms 17052 KB Output is correct
18 Correct 35 ms 17028 KB Output is correct
19 Correct 3 ms 16984 KB Output is correct
20 Correct 3 ms 16984 KB Output is correct
21 Incorrect 4 ms 16988 KB Output isn't correct
22 Halted 0 ms 0 KB -