답안 #658875

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
658875 2022-11-15T09:45:31 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 midSpaces = 0; midSpaces <= spaces; midSpaces++) {
				int removed = spaces - midSpaces;
				ans = (ans + 1LL * (removed+1) * 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();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -