Submission #459550

# Submission time Handle Problem Language Result Execution time Memory
459550 2021-08-08T15:59:21 Z erke A Huge Tower (CEOI10_tower) C++11
85 / 100
1000 ms 7292 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 1000005;
const int MOD = 1e9 + 9;

int a[N], dp[N];

signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, d;
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1, greater<int>());
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (j - 1 >= 1 && a[j - 1] <= a[i] + d) j--;
    dp[i] += (dp[i - 1] * (i - j + 1)) % MOD;
    dp[i] %= MOD;
  }
  cout << dp[n] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 1580 KB Output is correct
2 Execution timed out 1085 ms 1492 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 583 ms 5928 KB Output is correct
2 Execution timed out 1078 ms 5272 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 7292 KB Time limit exceeded
2 Halted 0 ms 0 KB -