Submission #487931

#TimeUsernameProblemLanguageResultExecution timeMemory
487931DDTerziev04A Huge Tower (CEOI10_tower)C++14
100 / 100
131 ms8700 KiB
#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 (stderr)

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