Submission #725071

# Submission time Handle Problem Language Result Execution time Memory
725071 2023-04-16T18:05:35 Z TheSahib Magneti (COCI21_magneti) C++17
110 / 110
455 ms 289396 KB
#include <bits/stdc++.h>
 
#pragma GCC optimize("O3")
 
#define ll long long
#define pii pair<int, int>
 
using namespace std;

const int MOD = 1e9 + 7;

const int MAX = 1e4 + 100;

int comb[MAX][MAX];
int dp[55][55][MAX];
int arr[55];

void preCalc(){
    comb[0][0] = 1;
    for (int i = 1; i < MAX; i++)
    {
        comb[i][0] = 1;
        for (int j = 1; j <= i; j++)
        {
            comb[i][j] = ((comb[i][j] + comb[i - 1][j]) % MOD + comb[i - 1][j - 1]) % MOD;
        }
    }
}

int main(){
    preCalc();
    int n, l; cin >> n >> l;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i + 1];
    }
    sort(arr + 1, arr + n + 1);
    
    dp[0][0][1] = 1;
    for (int i = 1; i <= n; i++)
    {
        int r = arr[i];
        for (int j = 1; j <= i; j++)
        {
            for (int d = 1; d <= l; d++)
            {
                dp[i][j][d] += (1ll * dp[i - 1][j - 1][d] * j) % MOD;
                if(r <= d){
                    dp[i][j][d] += 1ll * dp[i - 1][j][d - r] * (2 * j) % MOD;
                }
                dp[i][j][d] %= MOD;
                if(2 * r <= d){
                    dp[i][j][d] += (1ll * dp[i - 1][j + 1][d - 2 * r] * j) % MOD;
                }
                dp[i][j][d] %= MOD;
            }
        }
    }
    int ans = 0;
    for (int d = 1; d <= l; d++)
    {
        ans += 1ll * dp[n][1][d] * comb[l - d + n][n] % MOD;
        ans %= MOD;
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 437 ms 289260 KB Output is correct
2 Correct 321 ms 244116 KB Output is correct
3 Correct 318 ms 240928 KB Output is correct
4 Correct 307 ms 238956 KB Output is correct
5 Correct 321 ms 242348 KB Output is correct
6 Correct 352 ms 254652 KB Output is correct
7 Correct 349 ms 268212 KB Output is correct
8 Correct 347 ms 238628 KB Output is correct
9 Correct 325 ms 253176 KB Output is correct
10 Correct 302 ms 238684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 327 ms 240832 KB Output is correct
2 Correct 308 ms 238868 KB Output is correct
3 Correct 341 ms 240836 KB Output is correct
4 Correct 308 ms 238924 KB Output is correct
5 Correct 305 ms 240760 KB Output is correct
6 Correct 303 ms 239020 KB Output is correct
7 Correct 309 ms 240820 KB Output is correct
8 Correct 314 ms 238972 KB Output is correct
9 Correct 304 ms 238952 KB Output is correct
10 Correct 326 ms 238524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 315 ms 241120 KB Output is correct
2 Correct 313 ms 239692 KB Output is correct
3 Correct 307 ms 241148 KB Output is correct
4 Correct 310 ms 239784 KB Output is correct
5 Correct 321 ms 241052 KB Output is correct
6 Correct 306 ms 239396 KB Output is correct
7 Correct 321 ms 241024 KB Output is correct
8 Correct 309 ms 238796 KB Output is correct
9 Correct 319 ms 239744 KB Output is correct
10 Correct 309 ms 238908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 437 ms 289260 KB Output is correct
2 Correct 321 ms 244116 KB Output is correct
3 Correct 318 ms 240928 KB Output is correct
4 Correct 307 ms 238956 KB Output is correct
5 Correct 321 ms 242348 KB Output is correct
6 Correct 352 ms 254652 KB Output is correct
7 Correct 349 ms 268212 KB Output is correct
8 Correct 347 ms 238628 KB Output is correct
9 Correct 325 ms 253176 KB Output is correct
10 Correct 302 ms 238684 KB Output is correct
11 Correct 327 ms 240832 KB Output is correct
12 Correct 308 ms 238868 KB Output is correct
13 Correct 341 ms 240836 KB Output is correct
14 Correct 308 ms 238924 KB Output is correct
15 Correct 305 ms 240760 KB Output is correct
16 Correct 303 ms 239020 KB Output is correct
17 Correct 309 ms 240820 KB Output is correct
18 Correct 314 ms 238972 KB Output is correct
19 Correct 304 ms 238952 KB Output is correct
20 Correct 326 ms 238524 KB Output is correct
21 Correct 315 ms 241120 KB Output is correct
22 Correct 313 ms 239692 KB Output is correct
23 Correct 307 ms 241148 KB Output is correct
24 Correct 310 ms 239784 KB Output is correct
25 Correct 321 ms 241052 KB Output is correct
26 Correct 306 ms 239396 KB Output is correct
27 Correct 321 ms 241024 KB Output is correct
28 Correct 309 ms 238796 KB Output is correct
29 Correct 319 ms 239744 KB Output is correct
30 Correct 309 ms 238908 KB Output is correct
31 Correct 455 ms 289176 KB Output is correct
32 Correct 405 ms 273392 KB Output is correct
33 Correct 435 ms 289232 KB Output is correct
34 Correct 330 ms 250316 KB Output is correct
35 Correct 435 ms 289244 KB Output is correct
36 Correct 347 ms 242020 KB Output is correct
37 Correct 446 ms 289180 KB Output is correct
38 Correct 328 ms 251352 KB Output is correct
39 Correct 445 ms 289284 KB Output is correct
40 Correct 344 ms 254796 KB Output is correct
41 Correct 433 ms 289396 KB Output is correct
42 Correct 300 ms 239080 KB Output is correct
43 Correct 424 ms 289216 KB Output is correct
44 Correct 314 ms 244284 KB Output is correct
45 Correct 426 ms 289224 KB Output is correct
46 Correct 301 ms 238612 KB Output is correct
47 Correct 329 ms 255356 KB Output is correct
48 Correct 313 ms 248168 KB Output is correct
49 Correct 303 ms 239552 KB Output is correct
50 Correct 325 ms 238952 KB Output is correct