Submission #670566

# Submission time Handle Problem Language Result Execution time Memory
670566 2022-12-09T14:35:40 Z omikron123 A Huge Tower (CEOI10_tower) C++14
90 / 100
14 ms 2192 KB
// https://oj.uz/problem/view/CEOI10_tower

#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
using namespace std;

// 这个有点数学题:
// 假设前i-1个块(从小到大排序)可以组成的方案有ans_i-1个,设b_i是满足以下式子的j数量:
//     j < i, a_i <= a_j + d
// 可以证明对于任何一个i-1个块的方案,都有b_i+1种办法,可以把第i个块插入进去。
// 具体说:一种办法是放最下面,另外b_i种是放在满足这个条件的石头的上面,其它地方都不合适。
// 所以这个题就可以通过递推来解决了。

int n, d;
int a[100005];

typedef long long ll;

ll ans = 1;

int main() {
    scanf("%d %d", &n, &d);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    sort(a, a+n);
    int j = 0;
    for (int i = 0; i < n; i++) {
        while (j < i && a[j] + d < a[i]) {
            j++;
        }
        ans = ans * (i-j+1) % ((ll)1e9 + 9);
    }

    printf("%lld", ans);

    return 0;
}

Compilation message

tower.cpp: In function 'int main()':
tower.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d %d", &n, &d);
      |     ~~~~~^~~~~~~~~~~~~~~~~
tower.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 924 KB Output is correct
2 Correct 10 ms 976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 2176 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 2192 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -