# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
57136 | 2018-07-14T06:24:40 Z | 김세빈(#1653) | Skyscraper (JOI16_skyscraper) | C++11 | 84 ms | 6948 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; const int c = 5050; ll D[2][111][2][2][10101]; ll A[111]; ll n, k, ans; int main() { ll i, j, l, x, y; scanf("%lld%lld", &n, &k); for(i=1;i<=n;i++){ scanf("%lld", A+i); } sort(A+1, A+n+1); for(i=n;i>=1;i--) A[i] -= A[1]; D[0][0][0][0][0 + c] = 1; for(i=1;i<n;i++){ for(j=0;j<=i;j++){ for(l=-3030;l<=3030;l++){ // endpoints if(j){ D[i&1][j-1][1][0][l + A[i] + c] = (D[i&1][j-1][1][0][l + A[i] + c] + D[~i&1][j][0][0][l + c]) % mod; D[i&1][j-1][0][1][l + A[i] + c] = (D[i&1][j-1][0][1][l + A[i] + c] + D[~i&1][j][0][0][l + c]) % mod; } D[i&1][j][1][0][l - A[i] + c] = (D[i&1][j][1][0][l - A[i] + c] + D[~i&1][j][0][0][l + c]) % mod; D[i&1][j][0][1][l - A[i] + c] = (D[i&1][j][0][1][l - A[i] + c] + D[~i&1][j][0][0][l + c]) % mod; if(j){ D[i&1][j-1][1][1][l + A[i] + c] = (D[i&1][j-1][1][1][l + A[i] + c] + D[~i&1][j][0][1][l + c]) % mod; D[i&1][j-1][0][1][l + 2*A[i] + c] = (D[i&1][j-1][0][1][l + 2*A[i] + c] + D[~i&1][j][0][1][l + c]) % mod; } D[i&1][j][1][1][l - A[i] + c] = (D[i&1][j][1][1][l - A[i] + c] + D[~i&1][j][0][1][l + c]) % mod; D[i&1][j][0][1][l + c] = (D[i&1][j][0][1][l + c] + D[~i&1][j][0][1][l + c]) % mod; if(j){ D[i&1][j-1][1][0][l + 2*A[i] + c] = (D[i&1][j-1][1][0][l + 2*A[i] + c] + D[~i&1][j][1][0][l + c]) % mod; D[i&1][j-1][1][1][l + A[i] + c] = (D[i&1][j-1][1][1][l + A[i] + c] + D[~i&1][j][1][0][l + c]) % mod; } D[i&1][j][1][0][l + c] = (D[i&1][j][1][0][l + c] + D[~i&1][j][1][0][l + c]) % mod; D[i&1][j][1][1][l - A[i] + c] = (D[i&1][j][1][1][l - A[i] + c] + D[~i&1][j][1][0][l + c]) % mod; if(j){ D[i&1][j-1][1][1][l + 2*A[i] + c] = (D[i&1][j-1][1][1][l + 2*A[i] + c] + D[~i&1][j][1][1][l + c] * 2) % mod; } D[i&1][j][1][1][l + c] = (D[i&1][j][1][1][l + c] + D[~i&1][j][1][1][l + c] * 2) % mod; for(x=0;x<2;x++) for(y=0;y<2;y++){ // new group D[i&1][j+1][x][y][l - 2*A[i] + c] = (D[i&1][j+1][x][y][l - 2*A[i] + c] + D[~i&1][j][x][y][l + c] * (j + 1)) % mod; // merge two groups if(j > 1){ D[i&1][j-1][x][y][l + 2*A[i] + c] = (D[i&1][j-1][x][y][l + 2*A[i] + c] + D[~i&1][j][x][y][l + c] * (j - 1)) % mod; } // group endpoints D[i&1][j][x][y][l + c] = (D[i&1][j][x][y][l + c] + D[~i&1][j][x][y][l + c] * 2 * j) % mod; D[~i&1][j][x][y][l + c] = 0; } } } } for(l=-3030;l<=3030;l++){ if(0 <= l + A[n] * 2 && l + A[n] * 2 <= k) ans = (ans + D[~n&1][0][1][1][l + c]) % mod; if(0 <= l + A[n] && l + A[n] <= k) ans = (ans + D[~n&1][0][1][0][l + c]) % mod; if(0 <= l + A[n] && l + A[n] <= k) ans = (ans + D[~n&1][0][0][1][l + c]) % mod; } printf("%lld\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 248 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 5552 KB | Output is correct |
2 | Correct | 83 ms | 6576 KB | Output is correct |
3 | Correct | 83 ms | 6576 KB | Output is correct |
4 | Correct | 53 ms | 6736 KB | Output is correct |
5 | Correct | 55 ms | 6948 KB | Output is correct |
6 | Correct | 53 ms | 6948 KB | Output is correct |
7 | Correct | 60 ms | 6948 KB | Output is correct |
8 | Correct | 50 ms | 6948 KB | Output is correct |
9 | Correct | 84 ms | 6948 KB | Output is correct |
10 | Correct | 74 ms | 6948 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 248 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |