Submission #442847

# Submission time Handle Problem Language Result Execution time Memory
442847 2021-07-09T08:56:34 Z parsabahrami Skyscraper (JOI16_skyscraper) C++17
100 / 100
269 ms 84748 KB
/* I do it for the glory */
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second

const int N = 1e2 + 10, MOD = 1e9 + 7;
int dp[N][N][10 * N][3], A[N], n, L;

void add(int &x, int y) {
    x += y;
    if (x >= MOD) x -= MOD;
}

int main() {  
    scanf("%d%d", &n, &L);
    dp[0][0][0][0] = 1;
  	if (n < 2) return !printf("1\n");
    for (int i = 1; i <= n; i++) 
        scanf("%d", &A[i]);
    sort(A + 1, A + n + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int k = 0; k <= L; k++) {
                for (int t = 0; t <= min(j, 2); t++) {
                    int nk = k + (A[i] - A[i - 1]) * (2 * j - t);
                    if (nk > L) continue;
                    add(dp[i][j + 1][nk][t], 1ll * dp[i - 1][j][k][t] * (j + 1 - t) % MOD);
                    if (t < 2) 
                        add(dp[i][j + 1][nk][t + 1], dp[i - 1][j][k][t] * (2ll - t) % MOD);
                    if (t < 2 && j) 
                        add(dp[i][j][nk][t + 1], dp[i - 1][j][k][t] * (2ll - t) % MOD);
                    if (j > 1) 
                        add(dp[i][j - 1][nk][t], 1ll * dp[i - 1][j][k][t] * (j - 1) % MOD); 
                    if (j) 
                        add(dp[i][j][nk][t], dp[i - 1][j][k][t] * 1ll * (2 * j - t) % MOD);
                }
            }
        }
    }
    int ret = 0;
    for (int i = 0; i <= L; i++) 
        add(ret, dp[n][1][i][2]);
    printf("%d\n", ret);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d%d", &n, &L);
      |     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%d", &A[i]);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 2 ms 844 KB Output is correct
6 Correct 2 ms 844 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 2 ms 972 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 2 ms 1100 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 2 ms 1228 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 2 ms 844 KB Output is correct
6 Correct 2 ms 844 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 2 ms 972 KB Output is correct
13 Correct 1 ms 1100 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 1 ms 844 KB Output is correct
18 Correct 1 ms 1100 KB Output is correct
19 Correct 2 ms 1228 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
21 Correct 4 ms 3916 KB Output is correct
22 Correct 252 ms 76612 KB Output is correct
23 Correct 268 ms 72360 KB Output is correct
24 Correct 258 ms 79288 KB Output is correct
25 Correct 269 ms 75048 KB Output is correct
26 Correct 236 ms 72136 KB Output is correct
27 Correct 107 ms 58180 KB Output is correct
28 Correct 143 ms 64836 KB Output is correct
29 Correct 235 ms 84748 KB Output is correct
30 Correct 259 ms 73904 KB Output is correct