Submission #134134

# Submission time Handle Problem Language Result Execution time Memory
134134 2019-07-22T06:31:44 Z Just_Solve_The_Problem Skyscraper (JOI16_skyscraper) C++11
100 / 100
353 ms 20200 KB
#include <bits/stdc++.h>

using namespace std;

const int mod = (int)1e9 + 7;

int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}

int mul(int a, int b) {
  return a * 1LL * b % mod;
}

const int N = (int)107;

int dp[N][N][1007][2][2];
int a[N];
int n, L;

main() {
  scanf("%d %d", &n, &L);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  if (n == 1) {
    puts("1");
    return 0;
  }
  sort(a, a + n);
  for (int i = n - 1; i >= 1; i--) {
    a[i] -= a[i - 1];
  }
  a[0] = 0;
  dp[0][0][0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int s = 0; s <= L; s++) {
        for (int l = 0; l < 2; l++) {
          for (int r = 0; r < 2; r++) {
            int &res = dp[i][j][s][l][r];
            if (res == 0) continue;
            int nw = s + (2 * j - l - r) * a[i];
            if (nw > L) continue;
            
            if (i) {            
              if (!l) dp[i + 1][j][nw][1][r] = add(dp[i + 1][j][nw][1][r], mul(res, j - (i == n - 1 ? 0 : r)));
              if (!r) dp[i + 1][j][nw][l][1] = add(dp[i + 1][j][nw][l][1], mul(res, j - (i == n - 1 ? 0 : l)));
              dp[i + 1][j][nw][l][r] = add(dp[i + 1][j][nw][l][r], mul(res, 2 * j - l - r));
              
              if (j >= 1) 
                dp[i + 1][j - 1][nw][l][r] = add(dp[i + 1][j - 1][nw][l][r], mul(res, (j - l - r) * (j - 1) + (i == n - 1 ? l * r : 0)));
            }
            
            if (!l) dp[i + 1][j + 1][nw][1][r] = add(dp[i + 1][j + 1][nw][1][r], res);
            if (!r) dp[i + 1][j + 1][nw][l][1] = add(dp[i + 1][j + 1][nw][l][1], res);
            dp[i + 1][j + 1][nw][l][r] = add(dp[i + 1][j + 1][nw][l][r], res);
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= L; i++) {
    ans = add(ans, dp[n][1][i][1][1]);
  }
  printf("%d\n", ans);
}

Compilation message

skyscraper.cpp:23:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &L);
   ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &a[i]);
     ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 3 ms 656 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 3 ms 656 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 632 KB Output is correct
15 Correct 3 ms 632 KB Output is correct
16 Correct 3 ms 760 KB Output is correct
17 Correct 3 ms 760 KB Output is correct
18 Correct 3 ms 760 KB Output is correct
19 Correct 3 ms 760 KB Output is correct
20 Correct 3 ms 632 KB Output is correct
21 Correct 7 ms 1528 KB Output is correct
22 Correct 353 ms 20200 KB Output is correct
23 Correct 233 ms 8304 KB Output is correct
24 Correct 233 ms 11664 KB Output is correct
25 Correct 244 ms 9212 KB Output is correct
26 Correct 220 ms 8736 KB Output is correct
27 Correct 111 ms 9728 KB Output is correct
28 Correct 152 ms 11504 KB Output is correct
29 Correct 256 ms 15364 KB Output is correct
30 Correct 243 ms 9592 KB Output is correct