# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
946517 | 2024-03-14T17:42:44 Z | hariaakas646 | Skyscraper (JOI16_skyscraper) | C++17 | 185 ms | 242616 KB |
#include <bits/stdc++.h> using namespace std; #define scd(t) scanf("%d", &t) #define sclld(t) scanf("%lld", &t) #define forr(i, l, r) for(int i=l; i<r; i++) #define frange(i, l) forr(i, 0, l) #define pb push_back #define mp make_pair #define f first #define s second #define all(x) x.begin(), x.end() typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vii; typedef long long lli; typedef vector<vi> vvi; typedef vector<lli> vll; typedef vector<bool> vb; typedef set<int> seti; typedef multiset<int> mseti; void usaco() { freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin); // freopen("problem.out", "w", stdout); } const lli mod = 1e9 + 7; int main() { // usaco(); int n, l; scd(n); scd(l); vi vec(n); frange(i, n) scd(vec[i]); sort(all(vec)); vec.pb(1e6); if(n == 1) { printf("1"); return 0; } vector<vector<vll>> dp(n, vector<vll>(n+2, vll(3*(l+1)))); if(2*(vec[1] - vec[0]) <= l) dp[0][1][2*(vec[1] - vec[0])] = 1; if((vec[1] - vec[0]) <= l) dp[0][1][(vec[1] - vec[0])+l+1] = 2; dp[0][1][2*(l+1)] = 1; forr(i, 1, n) { forr(j, 1, n+1) { forr(k, 0, l+1) { int c = k - (2*j) * (vec[i+1] - vec[i]); if(c >= 0) { dp[i][j][k] += 2*j*dp[i-1][j][c] + dp[i-1][j-1][c] + dp[i-1][j+1][c] * j * (j+1); dp[i][j][k] %= mod; } c = k - (2*(j)-1) * (vec[i+1] - vec[i]); if(c >= 0) { dp[i][j][k+l+1] += (2*j-1)*dp[i-1][j][c+l+1] + dp[i-1][j-1][c+l+1] + dp[i-1][j+1][c+l+1] * (j * j); dp[i][j][k+l+1] %= mod; dp[i][j][k+l+1] += 2*j*dp[i-1][j][c] + 2*dp[i-1][j-1][c]; dp[i][j][k+l+1] %= mod; } c = k - (2*(j)-2) * (vec[i+1] - vec[i]); if(c >= 0) { dp[i][j][k+2*(l+1)] += (2*j-2)*dp[i-1][j][c+2*(l+1)] + (j!=2) * dp[i-1][j-1][c+2*(l+1)] + dp[i-1][j+1][c+2*(l+1)] * ((j-1) * j + (j == 1)); dp[i][j][k+2*(l+1)] %= mod; dp[i][j][k+2*(l+1)] += (j-1 + (j==1))*dp[i-1][j][c+l+1] + dp[i-1][j-1][c+l+1]; dp[i][j][k+2*(l+1)] %= mod; } } } } lli tot = 0; frange(i, l+1) tot += dp[n-1][1][i+2*(l+1)]; tot %= mod; printf("%lld", tot); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 436 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 1 ms | 2140 KB | Output is correct |
7 | Correct | 0 ms | 604 KB | Output is correct |
8 | Correct | 0 ms | 604 KB | Output is correct |
9 | Correct | 2 ms | 2140 KB | Output is correct |
10 | Correct | 0 ms | 696 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 604 KB | Output is correct |
2 | Correct | 1 ms | 940 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 856 KB | Output is correct |
5 | Correct | 1 ms | 860 KB | Output is correct |
6 | Correct | 1 ms | 860 KB | Output is correct |
7 | Correct | 0 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 600 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 1 ms | 860 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 436 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 1 ms | 2140 KB | Output is correct |
7 | Correct | 0 ms | 604 KB | Output is correct |
8 | Correct | 0 ms | 604 KB | Output is correct |
9 | Correct | 2 ms | 2140 KB | Output is correct |
10 | Correct | 0 ms | 696 KB | Output is correct |
11 | Correct | 0 ms | 604 KB | Output is correct |
12 | Correct | 1 ms | 940 KB | Output is correct |
13 | Correct | 1 ms | 604 KB | Output is correct |
14 | Correct | 1 ms | 856 KB | Output is correct |
15 | Correct | 1 ms | 860 KB | Output is correct |
16 | Correct | 1 ms | 860 KB | Output is correct |
17 | Correct | 0 ms | 604 KB | Output is correct |
18 | Correct | 1 ms | 600 KB | Output is correct |
19 | Correct | 1 ms | 604 KB | Output is correct |
20 | Correct | 1 ms | 860 KB | Output is correct |
21 | Correct | 1 ms | 1884 KB | Output is correct |
22 | Correct | 109 ms | 122792 KB | Output is correct |
23 | Correct | 185 ms | 238420 KB | Output is correct |
24 | Correct | 121 ms | 180308 KB | Output is correct |
25 | Correct | 166 ms | 241492 KB | Output is correct |
26 | Correct | 130 ms | 205472 KB | Output is correct |
27 | Correct | 50 ms | 59996 KB | Output is correct |
28 | Correct | 59 ms | 73568 KB | Output is correct |
29 | Correct | 106 ms | 139340 KB | Output is correct |
30 | Correct | 155 ms | 242616 KB | Output is correct |