Submission #658874

# Submission time Handle Problem Language Result Execution time Memory
658874 2022-11-15T09:42:06 Z Foxyy Magneti (COCI21_magneti) C++17
0 / 110
1000 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define Foxyy cin.tie(0); cout.sync_with_stdio(0); cout.tie(0);

const int MOD = 1e9+7;

struct Solver {
	int& n;
	int& l;
	vector<int>& r;
	
	vector<int> fac{};
	
	void getFac() {
		fac.resize(l+1);
		fac[0] = 1;
		for (int i = 1; i <= l; i++) {
			fac[i] = 1LL * fac[i-1] * i % MOD;
		}
	}
	
	ll fastPow(int base, int power) {
		if (power == 0) return 1;
		if (power % 2) return fastPow(base, power-1) * base % MOD;
		ll ret = fastPow(base, power/2);
		return ret*ret % MOD;
	}
	
	void solve() {
		if (n == 1) {
			cout << l << '\n';
			return;
		}
		
		getFac();
		
		int ans = 0;
		for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j) {
			int sum = r[i] + r[j];
			for (int k = 0; k < n; k++) if (k != i and k != j) {
				sum += 2*r[k] - 1;
			}
			int spaces = l - sum;
			if (spaces < 0) {
				continue;
			}
			
			for (int left = 0; left <= spaces; left++) {
				for (int right = 0; right <= spaces - left; right++) {
					int midSpaces = spaces - left - right;
//					cerr << i << ' ' << j << ' ' << left << ' ' << right << ' '
//						 << fac[n-2 + midSpaces] * fastPow(fac[midSpaces], MOD-2) % MOD << '\n';
					ans = (ans + fac[n-2 + midSpaces] * fastPow(fac[midSpaces], MOD-2) % MOD) % MOD;
				}
			}
		}
		cout << ans << '\n';
	}
};
 
signed main() {
	Foxyy
	
	int T = 1;
//	cin >> T;
	while(T--) {
		int n, l;
		cin >> n >> l;
		vector<int> r(n);
		for (auto& x : r) {
			cin >> x;
		}
		
		Solver solver{n, l, r};
		solver.solve();
	}
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1050 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 149 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1050 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -