답안 #205992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205992 2020-03-01T19:04:00 Z stefdasca Skyscraper (JOI16_skyscraper) C++14
100 / 100
304 ms 245328 KB
/*
        JOIOC 16-skyscraper


*/
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

// #define fisier 1

using namespace std;

typedef long long ll;


int add(int a, int b)
{
    int x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

int n, maxsum;
ll v[102];

ll dp[102][102][1002][3];
/*
    dp[i][j][k][l]:
    i - number of numbers placed
    j - number of connected components
    k - total sum currently (filling empty spaces with a_{i} (0-indexed)
    l - number of endpoints that are filled
*/

int solve(int i, int j, int k, int l)
{
    if(i > 0 && (j < 1 || l > 2 || k > maxsum)) // invalid conditions
        return 0;
    if(i == n)
        return (j == 1 && l == 2);
    if(dp[i][j][k][l] != -1)
        return dp[i][j][k][l];
    int s = (v[i + 1] - v[i]) * (2 * j - l) + k;
    dp[i][j][k][l] = 0;
    dp[i][j][k][l] = add(dp[i][j][k][l], mul((j + 1 - l), solve(i + 1, j + 1, s, l)));
    dp[i][j][k][l] = add(dp[i][j][k][l], mul((2 - l), solve(i + 1, j, s, l + 1)));
    dp[i][j][k][l] = add(dp[i][j][k][l], mul((2 - l), solve(i + 1, j + 1, s, l + 1)));
    dp[i][j][k][l] = add(dp[i][j][k][l], mul((j - 1), solve(i + 1, j - 1, s, l)));
    dp[i][j][k][l] = add(dp[i][j][k][l], mul((2 * j - l), solve(i + 1, j, s, l)));
    return dp[i][j][k][l];
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> maxsum;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    sort(v + 1, v + n + 1);
    if(n == 1)
    {
        cout << 1;
        return 0;
    }
    memset(dp, -1, sizeof(dp));
    v[0] = v[1];
    cout << solve(0, 0, 0, 0);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 134 ms 245240 KB Output is correct
3 Correct 135 ms 245112 KB Output is correct
4 Correct 132 ms 245116 KB Output is correct
5 Correct 133 ms 245160 KB Output is correct
6 Correct 138 ms 245120 KB Output is correct
7 Correct 136 ms 245112 KB Output is correct
8 Correct 133 ms 245116 KB Output is correct
9 Correct 133 ms 245112 KB Output is correct
10 Correct 136 ms 245220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 245188 KB Output is correct
2 Correct 134 ms 245112 KB Output is correct
3 Correct 141 ms 245088 KB Output is correct
4 Correct 132 ms 245328 KB Output is correct
5 Correct 137 ms 245112 KB Output is correct
6 Correct 134 ms 245112 KB Output is correct
7 Correct 135 ms 245112 KB Output is correct
8 Correct 136 ms 245184 KB Output is correct
9 Correct 141 ms 245240 KB Output is correct
10 Correct 135 ms 245112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 134 ms 245240 KB Output is correct
3 Correct 135 ms 245112 KB Output is correct
4 Correct 132 ms 245116 KB Output is correct
5 Correct 133 ms 245160 KB Output is correct
6 Correct 138 ms 245120 KB Output is correct
7 Correct 136 ms 245112 KB Output is correct
8 Correct 133 ms 245116 KB Output is correct
9 Correct 133 ms 245112 KB Output is correct
10 Correct 136 ms 245220 KB Output is correct
11 Correct 133 ms 245188 KB Output is correct
12 Correct 134 ms 245112 KB Output is correct
13 Correct 141 ms 245088 KB Output is correct
14 Correct 132 ms 245328 KB Output is correct
15 Correct 137 ms 245112 KB Output is correct
16 Correct 134 ms 245112 KB Output is correct
17 Correct 135 ms 245112 KB Output is correct
18 Correct 136 ms 245184 KB Output is correct
19 Correct 141 ms 245240 KB Output is correct
20 Correct 135 ms 245112 KB Output is correct
21 Correct 134 ms 245112 KB Output is correct
22 Correct 304 ms 245112 KB Output is correct
23 Correct 236 ms 245136 KB Output is correct
24 Correct 234 ms 245240 KB Output is correct
25 Correct 211 ms 245112 KB Output is correct
26 Correct 196 ms 245112 KB Output is correct
27 Correct 167 ms 245108 KB Output is correct
28 Correct 187 ms 245112 KB Output is correct
29 Correct 245 ms 245112 KB Output is correct
30 Correct 209 ms 245112 KB Output is correct