Submission #1090005

# Submission time Handle Problem Language Result Execution time Memory
1090005 2024-09-17T14:11:39 Z akamizane A Huge Tower (CEOI10_tower) C++17
5 / 100
85 ms 19840 KB
#include<bits/stdc++.h>
 
using namespace std;

using ll = long long;
using pii = pair<int,int>;
using db = double;

#define el cout << '\n'
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
template <class T1, class T2>void chmax(T1 &a, T2 b){a = max(a, b);}
template <class T1, class T2>void chmin(T1 &a, T2 b){a = min(a, b);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 1e9 + 9;;

template<typename T> T inv(T a, T m){ T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u; }
 
template<typename T>
class Modular{
public:
  long long x;
  constexpr Modular() {}
  template<typename U> Modular(U x){if(x < 0) x += mod(); this->x = x; }
 
  constexpr long long& operator()(){return x;}
  template<typename U> explicit operator U() const {return static_cast<U>(x);}
  constexpr static long long mod(){return T::value;}
 
  Modular& operator+= (const Modular &a){ x += a.x; if(x >= mod()) x -= mod(); return *this; }
  template<typename U> Modular& operator+=(const U& a){ return *this += Modular(a); }
  Modular& operator-= (const Modular &a){ x -= a.x; if(x < 0) x += mod(); return *this; }
  template<typename U> Modular& operator-=(const U& a){ return *this -= Modular(a); }
  Modular& operator*= (const Modular &a){ x = (x % mod()) * (a.x % mod()); x %= mod(); return *this; }
  Modular& operator/= (const Modular &a){ return *this *= Modular(inv(a.x, mod())); } 
 
  Modular& operator++(){ return *this += 1; }
  Modular operator++(int) { Modular res(*this); *this += 1; return res; }
  Modular& operator--(){ return *this -= 1; }
  Modular operator--(int){ Modular res(*this); *this -= 1; return res;}
 
  Modular operator-() const {return Modular(-x);} 
 
  template<typename U> friend std::ostream& operator<<(std::ostream& out, const Modular<U> &b);
  template<typename U> friend std::istream& operator>>(std::istream& in, Modular<U>& b);
};
 
template<typename T> Modular<T> operator+(const Modular<T>& a, const Modular<T>& b){ return Modular<T>(a) += b; }
template<typename T, typename U> Modular<T> operator+(const Modular<T>& a, U b){ return Modular<T>(a) += b; }
template<typename T, typename U> Modular<U> operator+(T a, const Modular<U>& b){ return Modular<U>(a) += b; }
 
template<typename T> Modular<T> operator-(const Modular<T>& a, const Modular<T>& b){ return Modular<T>(a) -= b; }
template<typename T, typename U> Modular<T> operator-(const Modular<T>& a, U b){ return Modular<T>(a) -= b; }
template<typename T, typename U> Modular<U> operator-(T a, const Modular<U>& b){ return Modular<U>(a) -= b; }
 
template<typename T> Modular<T> operator*(const Modular<T>& a, const Modular<T>& b){ return Modular<T>(a) *= b; }
template<typename T, typename U> Modular<T> operator*(const Modular<T>& a, U b){ return Modular<T>(a) *= b; }
template<typename T, typename U> Modular<U> operator*(T a, const Modular<U>& b){ return Modular<U>(a) *= b; }
 
template<typename T> Modular<T> operator/(const Modular<T>& a, const Modular<T>& b){ return Modular<T>(a) /= b; }
template<typename T, typename U> Modular<T> operator/(const Modular<T>& a, U b){ return Modular<T>(a) /= b; }
template<typename T, typename U> Modular<U> operator/(T a, const Modular<U>& b){ return Modular<U>(a) /= b; }
 
template<typename T, typename U> 
Modular<T> Pow(const Modular<T>& a, const U& b){ assert(b >= 0); Modular<T> x = a,res = 1; U p = b; while(p){ if(p & 1) res *= x; x *= x; p >>= 1; } return res; }
 
template<typename T> std::ostream& operator<<(std::ostream& out, const Modular<T> &a){ out << a.x; return out; }
template<typename T> std::istream& operator>>(std::istream& in, Modular<T> &a){ in >> a.x; a.x %= Modular<T>::mod(); return in; }
 
template<typename T> string to_string(const Modular<T> &a){ return to_string((int) a); }
 
using Mint = Modular<std::integral_constant<decay<decltype(mod)>::type, mod>>;

const int maxn = 3e5 + 5;

Mint f[maxn];

void solve(){
  ll n, k;
  cin >> n >> k;
  vector<ll> x(n);
  for (auto& a : x) cin >> a;
  sort(x.rbegin(), x.rend());
  Mint ans = 1;
  ll cur = 1;
  FOR(i, 1, n - 1){
    if (x[i - 1] - x[i] > k){
      ans *= f[cur];
      cur = 1;
    }
    else cur++;
  }
  cerr << cur;
  ans *= f[cur];
  cout << ans;
}


int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tests = 1;
  //cin >> tests;
  f[1] = 1;
  for (int i = 2; i < maxn; i++) f[i] = i * f[i - 1];
  for (int itest = 1; itest <= tests; itest++){
    cerr << "- TEST " << itest << ": \n";
    solve();
    el;
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 3672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 7056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 85 ms 19840 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -