# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136695 | 2019-07-26T07:14:39 Z | choikiwon | A Huge Tower (CEOI10_tower) | C++17 | 1000 ms | 18552 KB |
#include<bits/stdc++.h> using namespace std; const int mod = 1e9 + 9; int N, D; vector<int> fact, A, B; vector<int> dp[2]; int main() { scanf("%d %d", &N, &D); 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[0] = dp[1] = vector<int>(N); for(int i = 0; i < N; i++) { dp[1][i] = i % 2? mod - fact[N - i] : fact[N - i]; } for(int i = 0; i < N; i++) { int c = i & 1; int p = c ^ 1; for(int j = 0; j < N; j++) { int &ret = dp[c][j] = 0; ret += dp[p][j]; ret %= mod; if(B[i] > j) { ret += 1LL * dp[p][j + 1] * (B[i] - j) % mod; ret %= mod; } } } printf("%d", dp[(N - 1) & 1][0]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 252 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 253 ms | 644 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1067 ms | 1784 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1063 ms | 7716 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1065 ms | 18552 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |