Submission #865564

# Submission time Handle Problem Language Result Execution time Memory
865564 2023-10-24T10:22:59 Z nase7faraj A Huge Tower (CEOI10_tower) C++14
100 / 100
98 ms 8884 KB
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pll pair<long long , long long>
#define pii pair<int , int>
#define mii map <int , int>
#define mll map <long long , long long>
#define vi vector <int>
#define vl vector <long long>
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rev greater<int>()
#define RF(F) freopen(F , "r" , stdin ) 
#define WF(F) freopen(F , "w" , stdout) 
using namespace std ;

const ll INF = 1e9 ;
const int eps = 1e-7 ;
const int mod = 1e9 + 9 ;
const int MAX_N = 1e6 + 7 ;

int a[MAX_N] ;

void solve(int testCase){
    
    int n , k ;
    scanf("%d %d" , &n , &k) ;

    for(int i = 0 ; i < n ; i ++){
        scanf("%d" , &a[i]) ;
    }

    sort(a , a + n) ;

    int l = 0 , r = 0 ;
    ll ans = 1 ;
    
    while(l < n){

        while (r < n - 1 && (a[r + 1] - a[l]) <= k)r ++ ;
        
        ans = ans * (r - l + 1) ; 
        ans %= mod ;

        l ++ ;
    }

    
    printf("%lld\n" , ans) ;
}

int main() {

    int testCase = 1 ;

    for(int T = 1 ; T <= testCase ; T ++){
        solve(T) ;
    }

    return 0 ;
}

Compilation message

tower.cpp: In function 'void solve(int)':
tower.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d %d" , &n , &k) ;
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
tower.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf("%d" , &a[i]) ;
      |         ~~~~~^~~~~~~~~~~~~~
# 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 1 ms 600 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 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 756 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3164 KB Output is correct
2 Correct 8 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 4956 KB Output is correct
2 Correct 38 ms 4968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 8884 KB Output is correct
2 Correct 98 ms 8272 KB Output is correct