# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
496634 |
2021-12-21T17:20:24 Z |
JovanB |
Magneti (COCI21_magneti) |
C++17 |
|
182 ms |
54520 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;
const int N = 50;
const int LEN = 10000;
int add(int a, int b){ a += b; if(a >= MOD) a -= MOD; return a;}
int mul(int a, int b){ return (1LL*a*b)%MOD; }
int a[55];
int dp[55][55][LEN+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, len;
cin >> n >> len;
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=n; i++) a[i]--;
sort(a+1, a+1+n);
reverse(a+1, a+1+n);
dp[0][2][0] = 1;
for(int i=1; i<=n; i++){
for(int k=1; k<=i+2; k++){
int dva = 0, ddva = 0;
int jedan = 0, jjedan = 0;
for(int t=1; t<=len; t++){
/// spaja dva
ddva = add(ddva, dp[i-1][k+1][t-1]);
dva = add(dva, ddva);
dp[i][k][t] = add(dp[i][k][t], mul(k, dva));
/// pored jednog
if(t-1-a[i] >= 0) jjedan = add(jjedan, dp[i-1][k][t-1-a[i]]);
dp[i][k][t] = add(dp[i][k][t], mul(2*k-2, jjedan));
/// sam
if(k >= 2 && t-1-2*a[i] >= 0) dp[i][k][t] = add(dp[i][k][t], mul(k-2, dp[i-1][k-1][t-1-2*a[i]]));
}
}
}
cout << dp[n][1][len] << "\n";
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:32:17: warning: unused variable 'jedan' [-Wunused-variable]
32 | int jedan = 0, jjedan = 0;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
54432 KB |
Output is correct |
2 |
Correct |
5 ms |
6220 KB |
Output is correct |
3 |
Correct |
10 ms |
3448 KB |
Output is correct |
4 |
Correct |
4 ms |
972 KB |
Output is correct |
5 |
Correct |
14 ms |
4624 KB |
Output is correct |
6 |
Correct |
58 ms |
18472 KB |
Output is correct |
7 |
Correct |
71 ms |
32352 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
33 ms |
16360 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
3304 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
10 ms |
3276 KB |
Output is correct |
4 |
Correct |
2 ms |
844 KB |
Output is correct |
5 |
Correct |
10 ms |
3276 KB |
Output is correct |
6 |
Correct |
2 ms |
972 KB |
Output is correct |
7 |
Correct |
10 ms |
3256 KB |
Output is correct |
8 |
Correct |
2 ms |
844 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3148 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
4 ms |
3148 KB |
Output is correct |
4 |
Correct |
2 ms |
1740 KB |
Output is correct |
5 |
Correct |
5 ms |
3148 KB |
Output is correct |
6 |
Correct |
1 ms |
1228 KB |
Output is correct |
7 |
Correct |
4 ms |
3148 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
2 ms |
1740 KB |
Output is correct |
10 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
54432 KB |
Output is correct |
2 |
Correct |
5 ms |
6220 KB |
Output is correct |
3 |
Correct |
10 ms |
3448 KB |
Output is correct |
4 |
Correct |
4 ms |
972 KB |
Output is correct |
5 |
Correct |
14 ms |
4624 KB |
Output is correct |
6 |
Correct |
58 ms |
18472 KB |
Output is correct |
7 |
Correct |
71 ms |
32352 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
33 ms |
16360 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
10 ms |
3304 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
10 ms |
3276 KB |
Output is correct |
14 |
Correct |
2 ms |
844 KB |
Output is correct |
15 |
Correct |
10 ms |
3276 KB |
Output is correct |
16 |
Correct |
2 ms |
972 KB |
Output is correct |
17 |
Correct |
10 ms |
3256 KB |
Output is correct |
18 |
Correct |
2 ms |
844 KB |
Output is correct |
19 |
Correct |
2 ms |
844 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
4 ms |
3148 KB |
Output is correct |
22 |
Correct |
2 ms |
1484 KB |
Output is correct |
23 |
Correct |
4 ms |
3148 KB |
Output is correct |
24 |
Correct |
2 ms |
1740 KB |
Output is correct |
25 |
Correct |
5 ms |
3148 KB |
Output is correct |
26 |
Correct |
1 ms |
1228 KB |
Output is correct |
27 |
Correct |
4 ms |
3148 KB |
Output is correct |
28 |
Correct |
1 ms |
716 KB |
Output is correct |
29 |
Correct |
2 ms |
1740 KB |
Output is correct |
30 |
Correct |
1 ms |
716 KB |
Output is correct |
31 |
Correct |
174 ms |
54520 KB |
Output is correct |
32 |
Correct |
110 ms |
38028 KB |
Output is correct |
33 |
Correct |
174 ms |
54332 KB |
Output is correct |
34 |
Correct |
39 ms |
13632 KB |
Output is correct |
35 |
Correct |
182 ms |
54464 KB |
Output is correct |
36 |
Correct |
12 ms |
4436 KB |
Output is correct |
37 |
Correct |
182 ms |
54412 KB |
Output is correct |
38 |
Correct |
31 ms |
14116 KB |
Output is correct |
39 |
Correct |
174 ms |
54396 KB |
Output is correct |
40 |
Correct |
59 ms |
18484 KB |
Output is correct |
41 |
Correct |
178 ms |
54372 KB |
Output is correct |
42 |
Correct |
3 ms |
972 KB |
Output is correct |
43 |
Correct |
174 ms |
54344 KB |
Output is correct |
44 |
Correct |
19 ms |
7116 KB |
Output is correct |
45 |
Correct |
174 ms |
54424 KB |
Output is correct |
46 |
Correct |
1 ms |
588 KB |
Output is correct |
47 |
Correct |
46 ms |
19064 KB |
Output is correct |
48 |
Correct |
21 ms |
10880 KB |
Output is correct |
49 |
Correct |
4 ms |
1868 KB |
Output is correct |
50 |
Correct |
1 ms |
844 KB |
Output is correct |