Submission #393910

#TimeUsernameProblemLanguageResultExecution timeMemory
393910tcmmichaelb139A Huge Tower (CEOI10_tower)C++14
100 / 100
131 ms5164 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<double, double> pd; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<ll> vl; typedef vector<double> vd; typedef vector<string> vs; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<pd> vpd; #define vc vector #define pb push_back #define pf push_front #define rsz resize #define sz size #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define ub upper_bound #define lb lower_bound #define f first #define s second #define mp make_pair #define ln length #define IMX INT_MAX #define IMN INT_MIN void IO(string s = "") { ios_base::sync_with_stdio(0); cin.tie(0); if (s.length()) { freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } } int main() { IO(""); int n, d; cin >> n >> d; vi v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(all(v)); int r = 0, ans = 1; for (int l = 0; l < n; l++) { while (r < n-1 && v[r+1]-v[l] <= d) r++; int k = r-l+1; ans = (ans*1LL*k)%((int)1e9+9); } cout << ans << '\n'; } /* Stuff to look for * int overflow, array bounds * special cases (n=1) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */

Compilation message (stderr)

tower.cpp: In function 'void IO(std::string)':
tower.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   44 |         freopen((s+".in").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tower.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   45 |         freopen((s+".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...