Submission #874867

# Submission time Handle Problem Language Result Execution time Memory
874867 2023-11-18T01:53:06 Z tsumondai Magneti (COCI21_magneti) C++14
30 / 110
1000 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 1e6 + 5;
 
const int oo = 1e9, mod = 1e9 + 7;
 
int n, m, k, r[55], l, pas[1000][100005], x=0, dp[3][55][100005];

int mul(int a, int b) {
	return (int)a*b%mod;
}

int add(int a, int b) {
	return (int)(a+b)%mod;
}

void pascal() {
	foru(i,0,l+n) pas[i][0]=1;
	foru(i,1,l) {
		foru(j,1,min(n,i)) {
			pas[i][j]=add(pas[i-1][j], pas[i-1][j-1]);
		}
	}
	return;
}

void process() {
	cin >> n >> l;
	foru(i,1,n) cin >> r[i];
	sort(r+1, r+1+n);
	pascal();
	int x=0;
	dp[0][0][0]=1;
	foru(i,1,n) {
		x^=1;
		dp[x][0][0]=0;
		int R=r[i];
		foru(j,1,i) {
			foru(k,1,l) {
				dp[x][j][k]=dp[!x][j-1][k-1];
				if (k>=R) dp[x][j][k]=add(dp[x][j][k], mul(dp[!x][j][k-R], 2*j));
				if (k>=2*R-1) dp[x][j][k]=add(dp[x][j][k], mul(dp[!x][j+1][k-2*R+1], j*(j+1)));
			}
		}
	}

	int sol=0;

	foru(i,1,l) sol=add(sol, mul(dp[x][1][i], pas[l-i+n][n]));

	cout << sol;

    return;
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    process();
    //cerr << "Time elapsed: " << __TIME << " s.\n";
    return 0;
}

/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Calm down and get VOI 
Flow:
tìm số cách để sắp xếp n nam châm vào l ô sao cho không có nam châm nào nằm trong đoạn
x-r[i]+1, x+r[i]-1 
subtask 1: tất cả các nam châm đều bằng nhau
phải cách nhau ít nhất n-1
sử dụng công thức tính tổ hợp
subtask 2: n<=10

*/
# Verdict Execution time Memory Grader output
1 Runtime error 911 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2538 ms 524288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 265552 KB Output is correct
2 Correct 19 ms 189480 KB Output is correct
3 Correct 27 ms 265552 KB Output is correct
4 Correct 26 ms 257104 KB Output is correct
5 Correct 27 ms 265556 KB Output is correct
6 Correct 5 ms 47708 KB Output is correct
7 Correct 28 ms 265584 KB Output is correct
8 Correct 24 ms 240468 KB Output is correct
9 Correct 23 ms 226392 KB Output is correct
10 Correct 22 ms 222044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 911 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -