Submission #1047248

# Submission time Handle Problem Language Result Execution time Memory
1047248 2024-08-07T11:18:32 Z nima_aryan Skyscraper (JOI16_skyscraper) C++17
100 / 100
38 ms 3164 KB
/**
 *    author:  NimaAryan
 *    created: 2024-06-26 20:39:48
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#endif

using i64 = long long;

constexpr int mod = 1E9 + 7;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, L;
  cin >> N >> L;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  if (N == 1) {
    cout << 1 << "\n";
    return 0;
  }

  sort(A.begin(), A.end());
  A.push_back(10000);
  vector f(3, vector(1, vector<int>(L + 1)));
  f[0][0][0] = 1;
  for (int i = 0; i < N; ++i) {
    vector g(3, vector(i + 2, vector<int>(L + 1)));
    for (int p = 0; p < 3; ++p) {
      for (int c = 0; c <= i; ++c) {
        for (int s = 0; s <= L; ++s) {
          if (!f[p][c][s]) {
            continue;
          }
          int d = A[i + 1] - A[i];
          int new_s = s + (2 * c - p) * d;
          {
            if (c + 1 <= N && 0 <= new_s + 2 * d && new_s + 2 * d <= L) {
              add(g[p][c + 1][new_s + 2 * d], 1LL * f[p][c][s] * (c + 1 - p) % mod);
            }
            if (0 <= new_s && new_s <= L) {
              add(g[p][c][new_s], 1LL * f[p][c][s] * (2 * c - p) % mod);
            }
            if (c - 1 >= 1 && 0 <= new_s - 2 * d && new_s - 2 * d <= L) {
              add(g[p][c - 1][new_s - 2 * d], 1LL * f[p][c][s] * (c - 1) % mod);
            }
          }
          if (p < 2) {
            if (c + 1 <= N && 0 <= new_s + d && new_s + d <= L) {
              add(g[p + 1][c + 1][new_s + d], f[p][c][s] * (2 - p) % mod);
            }
            if (0 <= new_s - d && new_s - d <= L) {
              add(g[p + 1][c][new_s - d], f[p][c][s] * (2 - p) % mod);
            }
          }
        }
      }
    }
    f.swap(g);
  }

  int ans = 0;
  for (int l = 0; l <= L; ++l) {
    add(ans, f[2][1][l]);
  }
  cout << ans << "\n";

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 38 ms 2148 KB Output is correct
23 Correct 17 ms 3164 KB Output is correct
24 Correct 19 ms 2404 KB Output is correct
25 Correct 23 ms 3160 KB Output is correct
26 Correct 16 ms 2908 KB Output is correct
27 Correct 9 ms 1032 KB Output is correct
28 Correct 13 ms 1372 KB Output is correct
29 Correct 24 ms 2084 KB Output is correct
30 Correct 24 ms 3164 KB Output is correct