Submission #1067313

# Submission time Handle Problem Language Result Execution time Memory
1067313 2024-08-20T14:35:33 Z kojac A Huge Tower (CEOI10_tower) C++17
100 / 100
103 ms 19396 KB
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
 
#include <bits/stdc++.h>
using namespace std;
 
#define F first
#define S second
#define endl "\n"
 
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll MAXN = 2e5 + 10;
const ll MOD = 1e9+9;
const ll P = 333;

 
int32_t main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
 
    // freopen("shuffle.in","r",stdin);
    // freopen("shuffle.out","w",stdout);
 
    // int tt;
 
    // cin >> tt;
 
    // while(tt--){

        ll n, m;

        cin >> n >> m;

        ll dp[n+5];
        vector<ll> v;

        for(int i = 0; i < n; i++){
            ll x;
            cin >> x;

            v.push_back(x);
        }

        sort(v.begin(), v.end());


        ll l = n-1, r = n-1;

        while(l >= 0){
            if(l == 0){

                while(r >= l){
                    dp[r] = abs(r-l)+1;
                    r--;
                }

                break;
            }else{
                if(abs(v[r]-v[l-1]) <= m){
                    l--;
                }else{
                    dp[r] = abs(l-r)+1;
                    r--;
                }
            }
        }

        for(int i = 1; i < n; i++){
            dp[i] *= dp[i-1];

            dp[i] %= MOD;
        }

        cout << dp[n-1] << endl;

    
    // }
 
    
 
   
   
    return 0;
 
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1760 KB Output is correct
2 Correct 7 ms 1760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 6868 KB Output is correct
2 Correct 37 ms 6868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 19396 KB Output is correct
2 Correct 103 ms 18408 KB Output is correct