Submission #393555

# Submission time Handle Problem Language Result Execution time Memory
393555 2021-04-24T02:49:38 Z aaronhma A Huge Tower (CEOI10_tower) C++17
0 / 100
103 ms 5156 KB
// O(n log n + n)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;

#define all(x) begin(x), end(x)
#define FORE(i, a, b) for (ll i = a; i < b; i++)

const int MOD = 1e9 + 9; // 10^9 + 9 for "CEOI 2010 - A Huge Tower"

// INPUT
template <class T>
void read(T &x) { cin >> x; }

template <class T>
void read(vector<T> &a)
{
  FORE(i, 0, (int)a.size())
  read(a[i]);
}

template <class Arg, class... Args>
void read(Arg &first, Args &...rest)
{
  read(first);
  read(rest...);
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  // ans: We'll set the answer to 1.
  // j: Current index that we can build start from arr[0] (j = 0 is a dummy value)
  ll n, d, ans = 1, j = 0;
  read(n, d);

  vll arr(n);
  read(arr);

  // Sort the blocks in increasing order
  sort(all(arr));

  // Let i = starting index of the first block possible.
  FORE(i, 0, n) {
    // Find the maximum index possible that we can build starting from arr[i] as the base
    while (j < n && arr[j] - arr[i] <= d)
      j++;

    // j - i: Largest tower we can build when arr[i] is the base
    ans *- j - i;

    // Make the answer within range
    ans %= MOD;
  }

  cout << ans << "\n";

  return 0;
}

Compilation message

tower.cpp: In function 'int main()':
tower.cpp:55:14: warning: statement has no effect [-Wunused-value]
   55 |     ans *- j - i;
      |     ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 2256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 5156 KB Output isn't correct
2 Halted 0 ms 0 KB -