Submission #337012

#TimeUsernameProblemLanguageResultExecution timeMemory
337012SavicSA Huge Tower (CEOI10_tower)C++14
100 / 100
168 ms37088 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pb push_back #define all(a) a.begin(), a.end() #define ff(i,a,b) for(int i=a;i<=b;i++) #define fb(i,b,a) for(int i=b;i>=a;i--) using namespace std; typedef long long ll; typedef pair<ll,ll> pii; const int maxn = 1000005; const int inf = 1e9 + 5; const int mod = 1e9 + 9; int n, d; int niz[maxn]; ll ans[maxn]; vector<pii> vec; bool cmp(int s1, int s2){ return s1 > s2; } ll fak[maxn]; ll invz[maxn]; ll add(ll a, ll b){ return (a + b) % mod; } ll mul(ll a, ll b){ return (a * b) % mod; } ll power(ll a, ll b){ if(!b)return 1; ll pola = power(a, b / 2); pola = mul(pola, pola); if(b % 2)pola = mul(pola, a); return pola; } ll inv(ll a){ return power(a, mod - 2); } ll bin(int a, int b){ return mul(fak[a], mul(invz[b], invz[a - b])); } void init(){ fak[0] = 1; ff(i,1,maxn - 1)fak[i] = mul(fak[i - 1], i); invz[maxn - 1] = inv(fak[maxn - 1]); fb(i,maxn - 2, 0)invz[i] = mul(invz[i + 1], i + 1); } int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> n >> d; init(); ff(i,1,n)cin >> niz[i]; sort(niz + 1, niz + n + 1); int j = 1; ll br = 0; ff(i,1,n){ br++; while(niz[i] > niz[j] + d){ br--; j++; } ans[i] = br; } ff(i,1,n){ if(ans[i] >= ans[i + 1])vec.pb({(ll)i, ans[i]}); } // cout << endl; // for(auto c : vec)cout << c.fi << " " << c.se << endl; // cout << endl; ll rez = fak[vec[0].se]; int len = (int)vec.size(); ff(i,1,len - 1){ ll x = vec[i].fi; ll y = vec[i].se; rez = mul(rez, fak[y]); if(x - y + 1 <= vec[i - 1].fi){ ll presek = vec[i - 1].fi - (x - y + 1) + 1; rez = mul(rez, invz[presek]); } } cout << rez << endl; return 0; } /** 7 4 1 2 3 4 5 6 7 4 1 1 2 3 100 6 9 10 20 20 10 10 20 // probati bojenje sahovski ili slicno **/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...