답안 #372809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372809 2021-03-01T20:36:39 Z MiricaMatei Skyscraper (JOI16_skyscraper) C++14
100 / 100
173 ms 70124 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 105;
const int MAXL = 1005;
const int MOD = 1e9 + 7;

int a[MAXN];
int dp[MAXN][MAXN][MAXL][5];

int main() {
  //freopen("date.in", "r", stdin);
  //freopen("date.out", "w", stdout);

  int n, l;
  scanf("%d%d", &n, &l);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);

  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);

  dp[1][0][0][0] = 1;
  dp[1][0][0][1] = 2;
  dp[1][0][0][2] = 1;
  for (int i = 1; i < n; ++i) {
    int dif = a[i] - a[i + 1];
    for (int j = 0; j <= i + 1; ++j) {
      for (int s = 0; s <= l; ++s) {
        for (int e = 0; e <= 2; ++e) {
          int ns = s + dif * (2 * j + 2 - e);
          if (ns > l)
            continue;
          if (j - 1 >= 0)
            dp[i + 1][j - 1][ns][e] = (dp[i + 1][j - 1][ns][e] + 1LL * j * dp[i][j][s][e]) % MOD;
          dp[i + 1][j][ns][e] = (dp[i + 1][j][ns][e] + 1LL * (2 * j + 2 - e) * dp[i][j][s][e]) % MOD;
          dp[i + 1][j + 1][ns][e] = (dp[i + 1][j + 1][ns][e] + 1LL * (j + 2 - e) * dp[i][j][s][e]) % MOD;

          if (e + 1 <= 2)
            dp[i + 1][j][ns][e + 1] = (dp[i + 1][j][ns][e + 1] + 1LL * (2 - e) * dp[i][j][s][e]) % MOD;
          if (e + 1 <= 2)
            dp[i + 1][j + 1][ns][e + 1] = (dp[i + 1][j + 1][ns][e + 1] + 1LL * (2 - e) * dp[i][j][s][e]) % MOD;
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i <= l; ++i)
    ans = (ans + dp[n][0][i][2]) % MOD;

  printf("%d\n", ans);

  return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |   scanf("%d%d", &n, &l);
      |   ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 876 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 876 KB Output is correct
12 Correct 1 ms 1004 KB Output is correct
13 Correct 1 ms 1004 KB Output is correct
14 Correct 1 ms 1004 KB Output is correct
15 Correct 2 ms 1004 KB Output is correct
16 Correct 1 ms 1132 KB Output is correct
17 Correct 1 ms 748 KB Output is correct
18 Correct 1 ms 1004 KB Output is correct
19 Correct 1 ms 1004 KB Output is correct
20 Correct 1 ms 1004 KB Output is correct
21 Correct 3 ms 3436 KB Output is correct
22 Correct 122 ms 61548 KB Output is correct
23 Correct 153 ms 68076 KB Output is correct
24 Correct 131 ms 67436 KB Output is correct
25 Correct 148 ms 70124 KB Output is correct
26 Correct 132 ms 65644 KB Output is correct
27 Correct 60 ms 40044 KB Output is correct
28 Correct 73 ms 45804 KB Output is correct
29 Correct 122 ms 66156 KB Output is correct
30 Correct 173 ms 69860 KB Output is correct