# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
57163 | 2018-07-14T07:44:13 Z | 김세빈(#1653) | Skyscraper (JOI16_skyscraper) | C++11 | 182 ms | 5656 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; ll D[2][111][3][1010]; ll A[111]; ll n, k, ans; int main() { ll i, j, l, x, t; scanf("%lld%lld", &n, &k); for(i=1;i<=n;i++){ scanf("%lld", A+i); } if(n == 1){ printf("1\n"); return 0; } sort(A+1, A+n+1); D[0][0][0][0] = 1; for(i=1;i<n;i++){ for(j=0;j<=i;j++){ for(l=0;l<=k;l++){ // endpoints t = l + (A[i] - A[i-1]) * j * 2; if(t <= k){ if(j){ D[i&1][j-1][1][t] = (D[i&1][j-1][1][t] + D[~i&1][j][0][l] * (ll)2) % mod; } D[i&1][j][1][t] = (D[i&1][j][1][t] + D[~i&1][j][0][l] * (ll)2) % mod; } t = l + (A[i] - A[i-1]) * (j * 2 + 1); if(t <= k){ if(j){ D[i&1][j-1][2][t] = (D[i&1][j-1][2][t] + D[~i&1][j][1][l]) % mod; D[i&1][j-1][1][t] = (D[i&1][j-1][1][t] + D[~i&1][j][1][l]) % mod; } D[i&1][j][2][t] = (D[i&1][j][2][t] + D[~i&1][j][1][l]) % mod; D[i&1][j][1][t] = (D[i&1][j][1][t] + D[~i&1][j][1][l]) % mod; } t = l + (A[i] - A[i-1]) * (j * 2 + 2); if(t <= k){ if(j){ D[i&1][j-1][2][t] = (D[i&1][j-1][2][t] + D[~i&1][j][2][l] * (ll)2) % mod; } D[i&1][j][2][t] = (D[i&1][j][2][t] + D[~i&1][j][2][l] * (ll)2) % mod; } for(x=0;x<3;x++){ t = l + (A[i] - A[i-1]) * (j * 2 + x); if(t <= k){ // new group D[i&1][j+1][x][t] = (D[i&1][j+1][x][t] + D[~i&1][j][x][l] * (ll)(j + 1)) % mod; // merge two groups if(j > 1){ D[i&1][j-1][x][t] = (D[i&1][j-1][x][t] + D[~i&1][j][x][l] * (ll)(j - 1)) % mod; } // group endpoints D[i&1][j][x][t] = (D[i&1][j][x][t] + D[~i&1][j][x][l] * (ll)2 * j) % mod; } D[~i&1][j][x][l] = 0; } } } } for(i=0;i<=k;i++){ t = i + (A[n] - A[n-1]) * 2; if(t <= k) ans = (ans + D[~n&1][0][2][i]) % mod; t = i + (A[n] - A[n-1]); if(t <= k) ans = (ans + D[~n&1][0][1][i]) % mod; } printf("%lld\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 2 ms | 392 KB | Output is correct |
4 | Correct | 4 ms | 648 KB | Output is correct |
5 | Correct | 4 ms | 856 KB | Output is correct |
6 | Correct | 4 ms | 880 KB | Output is correct |
7 | Correct | 3 ms | 880 KB | Output is correct |
8 | Correct | 2 ms | 880 KB | Output is correct |
9 | Correct | 5 ms | 880 KB | Output is correct |
10 | Correct | 3 ms | 880 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 956 KB | Output is correct |
2 | Correct | 3 ms | 1000 KB | Output is correct |
3 | Correct | 3 ms | 1000 KB | Output is correct |
4 | Correct | 3 ms | 1000 KB | Output is correct |
5 | Correct | 4 ms | 1000 KB | Output is correct |
6 | Correct | 4 ms | 1004 KB | Output is correct |
7 | Correct | 3 ms | 1004 KB | Output is correct |
8 | Correct | 3 ms | 1004 KB | Output is correct |
9 | Correct | 4 ms | 1004 KB | Output is correct |
10 | Correct | 3 ms | 1004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 2 ms | 392 KB | Output is correct |
4 | Correct | 4 ms | 648 KB | Output is correct |
5 | Correct | 4 ms | 856 KB | Output is correct |
6 | Correct | 4 ms | 880 KB | Output is correct |
7 | Correct | 3 ms | 880 KB | Output is correct |
8 | Correct | 2 ms | 880 KB | Output is correct |
9 | Correct | 5 ms | 880 KB | Output is correct |
10 | Correct | 3 ms | 880 KB | Output is correct |
11 | Correct | 4 ms | 956 KB | Output is correct |
12 | Correct | 3 ms | 1000 KB | Output is correct |
13 | Correct | 3 ms | 1000 KB | Output is correct |
14 | Correct | 3 ms | 1000 KB | Output is correct |
15 | Correct | 4 ms | 1000 KB | Output is correct |
16 | Correct | 4 ms | 1004 KB | Output is correct |
17 | Correct | 3 ms | 1004 KB | Output is correct |
18 | Correct | 3 ms | 1004 KB | Output is correct |
19 | Correct | 4 ms | 1004 KB | Output is correct |
20 | Correct | 3 ms | 1004 KB | Output is correct |
21 | Correct | 4 ms | 1640 KB | Output is correct |
22 | Correct | 155 ms | 4312 KB | Output is correct |
23 | Correct | 178 ms | 5392 KB | Output is correct |
24 | Correct | 149 ms | 5392 KB | Output is correct |
25 | Correct | 182 ms | 5432 KB | Output is correct |
26 | Correct | 170 ms | 5432 KB | Output is correct |
27 | Correct | 53 ms | 5432 KB | Output is correct |
28 | Correct | 55 ms | 5432 KB | Output is correct |
29 | Correct | 122 ms | 5504 KB | Output is correct |
30 | Correct | 146 ms | 5656 KB | Output is correct |