Submission #670566

#TimeUsernameProblemLanguageResultExecution timeMemory
670566omikron123A Huge Tower (CEOI10_tower)C++14
90 / 100
14 ms2192 KiB
// 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 (stderr)

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 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...