Submission #487931

# Submission time Handle Problem Language Result Execution time Memory
487931 2021-11-17T06:55:59 Z DDTerziev04 A Huge Tower (CEOI10_tower) C++14
100 / 100
131 ms 8700 KB
#include<iostream>
#include<algorithm>
using namespace std;

const int MAXN=1e6, MOD=1e9+9;

int a[MAXN];

int BinSearch(int l, int r, int x)
{
   int ans;
   while(l<=r)
   {
      int mid=l+(r-l)/2;

      if(a[mid]<=x)
      {
         ans=mid;
         r=mid-1;
      }
      else
      {
         l=mid+1;
      }
   }

   return ans;
}

int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);

   int n, d;
   cin >> n >> d;

   for(int i=0; i<n; i++)
   {
      cin >> a[i];
   }
   sort(a, a+n);
   reverse(a, a+n);


   long long ans=1;
   int pr=0;
   while(pr<n)
   {
      int idx=pr+1;
      while(idx<n && a[idx-1]-a[idx]<=d)
      {
         idx++;
      }
      idx--;

      long long res=1;
      for(int i=pr+1; i<=idx; i++)
      {
         int x=BinSearch(pr, i, a[i]+d);

         res=(res*(i-x+1))%MOD;
      }
      pr=idx+1;

      ans=(ans*res)%MOD;
   }

   cout << ans << "\n";

   return 0;
}

Compilation message

tower.cpp: In function 'int BinSearch(int, int, int)':
tower.cpp:27:11: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |    return ans;
      |           ^~~
tower.cpp: In function 'int main()':
tower.cpp:62:21: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |          res=(res*(i-x+1))%MOD;
      |                    ~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 976 KB Output is correct
2 Correct 10 ms 976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 3656 KB Output is correct
2 Correct 46 ms 3668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 8700 KB Output is correct
2 Correct 131 ms 8136 KB Output is correct