Submission #886964

# Submission time Handle Problem Language Result Execution time Memory
886964 2023-12-13T09:31:21 Z Alora Magneti (COCI21_magneti) C++17
110 / 110
59 ms 13172 KB
#include <bits/stdc++.h>
#define Alora "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define f first
#define se second
#define pii pair<int, int>
#define getbit(i, j) ((i >> j) & 1)
#define all(v) v.begin(), v.end()
#define pb push_back
#define maxn 10088
const int M = 1e9 + 7;
using namespace std;
int n, l, r[55];
ll res, C[55][maxn], gt[55], dp[2][55][maxn];
void add(ll &x, ll y){x = (x + y) % M;}
ll mul(ll x, ll y) {return x*y % M;}

void pre(){
    fi(i, 1, l + n) C[0][i] = 1;
    C[1][1] = 1;
    fi(i, 2, l + n){
        fi(j, 1, min(50, i)){
            add(C[j][i], C[j][i - 1] + C[j - 1][i - 1]);
        }
    }
    gt[0] = 1;
    fi(i, 1, n) gt[i] = 1ll*gt[i - 1]*i % M;
}

void sub1(){
    if(n == 1) {cout << l; exit(0);}
    int len = l - (1 + r[1]*(n - 1));
    if(len < 0){cout << 0; exit(0);}
    len += n;
    cout << C[n][len]*gt[n] % M;
    exit(0);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	if(fopen(Alora".inp", "r")){
    freopen(Alora".inp", "r", stdin);
    freopen(Alora".out", "w", stdout);}
    cin >> n >> l;
    pre();
    fi(i, 1, n) cin >> r[i];
    sort(r + 1, r + n + 1);
    if(r[1] == r[n]) sub1();
    dp[0][0][0] = 1;
    fi(i, 0, n - 1){
        fi(j, 0, i){
            fi(d, 0, l) if(dp[0][j][d]){
                ll x = dp[0][j][d];
                add(dp[1][j + 1][d + 1], mul(x, j + 1));
                if(d + r[i + 1] <= l) add(dp[1][j][d + r[i + 1]], mul(x, 2*j));
                if(j && d + 2*r[i + 1] - 1 <= l) add(dp[1][j - 1][d + 2*r[i + 1] - 1], mul(x, j - 1));
            }
        }
        swap(dp[0], dp[1]);
        fi(j, 0, i) fi(d, 0, l) dp[1][j][d] = 0;
    }
    fi(d, 1, l) add(res, mul(dp[0][1][d], C[n][l - d + n]));
    cout << res;
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:45:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     freopen(Alora".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     freopen(Alora".out", "w", stdout);}
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 3676 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3416 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 13076 KB Output is correct
2 Correct 5 ms 12124 KB Output is correct
3 Correct 9 ms 13148 KB Output is correct
4 Correct 6 ms 12636 KB Output is correct
5 Correct 10 ms 12980 KB Output is correct
6 Correct 7 ms 11864 KB Output is correct
7 Correct 9 ms 13148 KB Output is correct
8 Correct 8 ms 11100 KB Output is correct
9 Correct 7 ms 12180 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 10844 KB Output is correct
2 Correct 11 ms 10844 KB Output is correct
3 Correct 15 ms 11068 KB Output is correct
4 Correct 14 ms 10844 KB Output is correct
5 Correct 15 ms 11072 KB Output is correct
6 Correct 10 ms 10844 KB Output is correct
7 Correct 16 ms 10844 KB Output is correct
8 Correct 7 ms 10844 KB Output is correct
9 Correct 11 ms 10844 KB Output is correct
10 Correct 7 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 3676 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3416 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
11 Correct 10 ms 13076 KB Output is correct
12 Correct 5 ms 12124 KB Output is correct
13 Correct 9 ms 13148 KB Output is correct
14 Correct 6 ms 12636 KB Output is correct
15 Correct 10 ms 12980 KB Output is correct
16 Correct 7 ms 11864 KB Output is correct
17 Correct 9 ms 13148 KB Output is correct
18 Correct 8 ms 11100 KB Output is correct
19 Correct 7 ms 12180 KB Output is correct
20 Correct 1 ms 3420 KB Output is correct
21 Correct 18 ms 10844 KB Output is correct
22 Correct 11 ms 10844 KB Output is correct
23 Correct 15 ms 11068 KB Output is correct
24 Correct 14 ms 10844 KB Output is correct
25 Correct 15 ms 11072 KB Output is correct
26 Correct 10 ms 10844 KB Output is correct
27 Correct 16 ms 10844 KB Output is correct
28 Correct 7 ms 10844 KB Output is correct
29 Correct 11 ms 10844 KB Output is correct
30 Correct 7 ms 10840 KB Output is correct
31 Correct 48 ms 13148 KB Output is correct
32 Correct 40 ms 12616 KB Output is correct
33 Correct 48 ms 13148 KB Output is correct
34 Correct 21 ms 12380 KB Output is correct
35 Correct 59 ms 13148 KB Output is correct
36 Correct 11 ms 12548 KB Output is correct
37 Correct 53 ms 13160 KB Output is correct
38 Correct 25 ms 11388 KB Output is correct
39 Correct 46 ms 13148 KB Output is correct
40 Correct 20 ms 12892 KB Output is correct
41 Correct 43 ms 13148 KB Output is correct
42 Correct 7 ms 11356 KB Output is correct
43 Correct 40 ms 13172 KB Output is correct
44 Correct 13 ms 12380 KB Output is correct
45 Correct 38 ms 13148 KB Output is correct
46 Correct 6 ms 13148 KB Output is correct
47 Correct 20 ms 12636 KB Output is correct
48 Correct 20 ms 11508 KB Output is correct
49 Correct 8 ms 12636 KB Output is correct
50 Correct 8 ms 10844 KB Output is correct