Submission #136723

#TimeUsernameProblemLanguageResultExecution timeMemory
136723choikiwonA Huge Tower (CEOI10_tower)C++17
85 / 100
1073 ms1144 KiB
#include<bits/stdc++.h> using namespace std; const int mod = 1e9 + 9; int N, D; vector<int> fact, A, B; vector<int> dp; int main() { scanf("%d %d", &N, &D); if(N > 100000) { return 0; } fact.resize(N + 1); fact[0] = 1; for(int i = 1; i <= N; i++) { fact[i] = 1LL * fact[i - 1] * i % mod; } A.resize(N); for(int i = 0; i < N; i++) { scanf("%d", &A[i]); } sort(A.begin(), A.end()); B.resize(N); int pos = N - 1; for(int i = N - 1; i >= 0; i--) { while(pos >= 0 && A[pos] > A[i] + D) pos--; B[i] = N - 1 - pos; } dp = vector<int>(N); for(int i = 0; i < N; i++) { dp[i] = i % 2? mod - fact[N - i] : fact[N - i]; } for(int i = 0; i < N; i++) { for(int j = 0; j < N - i; j++) { if(B[i] > j) { dp[j] += 1LL * dp[j + 1] * (B[i] - j) % mod; dp[j] %= mod; } } } printf("%d", dp[0]); }

Compilation message (stderr)

tower.cpp: In function 'int main()':
tower.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &D);
     ~~~~~^~~~~~~~~~~~~~~~~
tower.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
#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...