답안 #96538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96538 2019-02-10T07:05:49 Z tichuot97 Skyscraper (JOI16_skyscraper) C++14
100 / 100
234 ms 143992 KB
#include <iostream>
#include <algorithm>
#include <cstring>
#include <time.h>
#include <set>

using namespace std;

const int maxN = 110, maxS = 1010, oo = 23041997, modP = 1e9 + 7;

int f[maxN][maxN][maxS][3], n, a[maxN], l;

int dp(int i, int cc, int s, int e) {
    if (s > l) return 0;
    if (i > n) return cc == 1 && e == 2;
    if (f[i][cc][s][e] != -1) return f[i][cc][s][e];
    int tmp = 0;
    int cost = s + (2 * cc - e) * (a[i] - a[i - 1]);
    // ** Add new component **
    // 1. Endpoints:
    if (e < 2) {
        tmp = (1ll * tmp + 1ll * dp(i + 1, cc + 1, cost, e + 1) * (2 - e)) % modP;
        // Merge new one with sth else immediately:
        if (i == n && cc == 1 && e == 1)
            tmp = (1ll * tmp + 1ll * dp(i + 1, cc, cost, e + 1)) % modP;
        else if (cc - e)
            tmp = (1ll * tmp + 1ll * dp(i + 1, cc, cost, e + 1) * (2 - e) * (cc - e)) % modP;
    }
    // 2. Middle:
    tmp = (tmp + dp(i + 1, cc + 1, cost, e)) % modP;
    // ** Add to existing component **
    // 1. Endpoints:
    if (e) tmp = (1ll * tmp + 1ll * dp(i + 1, cc, cost, e) * e) % modP;
    // 2. Middle:
    if (cc - e) tmp = (1ll * tmp + 1ll * dp(i + 1, cc, cost, e) * (2 * (cc - e))) % modP;
    // ** Merge existing components **
    // 1. Endpoint with middle:
    if (e && cc - e)
        tmp = (1ll * tmp + 1ll * dp(i + 1, cc - 1, cost, e) * e * (cc - e)) % modP;
    // 2. Middle with middle:
    if (cc - e >= 2)
        tmp = (1ll * tmp + 1ll * dp(i + 1, cc - 1, cost, e) * (cc - e) * (cc - e - 1)) % modP;
    // 3. Endpoint with endpoint:
    if (e == 2 && cc == 2 && i == n)
        tmp = (1ll * tmp + 1ll * dp(i + 1, cc - 1, cost, e)) % modP;
    return f[i][cc][s][e] = tmp;
}

int main() {
    cin >> n >> l;
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    if (n == 1) { cout << 1; return 0; }
    sort(a + 1, a + n + 1);
    memset(f, 255, sizeof(f));
    cout << dp(1, 0, 0, 0);
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:51:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
                                  ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 97 ms 143864 KB Output is correct
3 Correct 96 ms 143864 KB Output is correct
4 Correct 97 ms 143736 KB Output is correct
5 Correct 96 ms 143864 KB Output is correct
6 Correct 99 ms 143808 KB Output is correct
7 Correct 99 ms 143864 KB Output is correct
8 Correct 95 ms 143736 KB Output is correct
9 Correct 95 ms 143992 KB Output is correct
10 Correct 96 ms 143744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 143864 KB Output is correct
2 Correct 104 ms 143752 KB Output is correct
3 Correct 95 ms 143864 KB Output is correct
4 Correct 97 ms 143836 KB Output is correct
5 Correct 96 ms 143868 KB Output is correct
6 Correct 97 ms 143788 KB Output is correct
7 Correct 108 ms 143808 KB Output is correct
8 Correct 96 ms 143736 KB Output is correct
9 Correct 97 ms 143800 KB Output is correct
10 Correct 95 ms 143736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 97 ms 143864 KB Output is correct
3 Correct 96 ms 143864 KB Output is correct
4 Correct 97 ms 143736 KB Output is correct
5 Correct 96 ms 143864 KB Output is correct
6 Correct 99 ms 143808 KB Output is correct
7 Correct 99 ms 143864 KB Output is correct
8 Correct 95 ms 143736 KB Output is correct
9 Correct 95 ms 143992 KB Output is correct
10 Correct 96 ms 143744 KB Output is correct
11 Correct 108 ms 143864 KB Output is correct
12 Correct 104 ms 143752 KB Output is correct
13 Correct 95 ms 143864 KB Output is correct
14 Correct 97 ms 143836 KB Output is correct
15 Correct 96 ms 143868 KB Output is correct
16 Correct 97 ms 143788 KB Output is correct
17 Correct 108 ms 143808 KB Output is correct
18 Correct 96 ms 143736 KB Output is correct
19 Correct 97 ms 143800 KB Output is correct
20 Correct 95 ms 143736 KB Output is correct
21 Correct 95 ms 143868 KB Output is correct
22 Correct 234 ms 143864 KB Output is correct
23 Correct 123 ms 143836 KB Output is correct
24 Correct 170 ms 143856 KB Output is correct
25 Correct 143 ms 143864 KB Output is correct
26 Correct 127 ms 143852 KB Output is correct
27 Correct 118 ms 143736 KB Output is correct
28 Correct 143 ms 143864 KB Output is correct
29 Correct 167 ms 143864 KB Output is correct
30 Correct 133 ms 143868 KB Output is correct