Submission #556557

#TimeUsernameProblemLanguageResultExecution timeMemory
556557InternetPerson10Boat (APIO16_boat)C++17
0 / 100
438 ms6276 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; const ll MOD = 1e9 + 7; ll modpow(ll n, ll e) { if(e == 0) return 1; ll x = modpow(n, e/2); x *= x; x %= MOD; if(e%2) { x *= n; x %= MOD; } return x; } ll modinv(ll n) { return modpow(n, MOD - 2); } ll smallinv[2001]; ll binom(ll n, ll k) { // Assumes k is quite small if(k > n) return 0; if(k == n) return 1; ll ans = 1; for(ll i = n-k+1; i <= n; i++) { ans *= i; ans %= MOD; } for(ll i = 1; i <= k; i++) { ans *= modinv(i); ans %= MOD; } return ans; } void precalc() { smallinv[0] = 1; for(int i = 1; i <= 2000; i++) { smallinv[i] = (smallinv[i-1] * i) % MOD; } for(int i = 0; i <= 2000; i++) { smallinv[i] = modinv(smallinv[i]); } } ll ans[501][1001], pref[501][1001]; int main() { ios::sync_with_stdio(false); cin.tie(0); precalc(); int n; cin >> n; vector<int> nums(2 * n), a(n+1), b(n+1); for(int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; b[i]++; nums[2*i - 2] = a[i]; nums[2*i - 1] = b[i]; } sort(nums.begin(), nums.end()); nums.resize(unique(nums.begin(), nums.end()) - nums.begin()); for(int i = 1; i <= n; i++) { for(int j = 1; j < nums.size(); j++) { if(!(a[i] <= nums[j-1] && nums[j] <= b[i])) { pref[i][j] = ans[i][j] + pref[i][j-1] + pref[i-1][j] - pref[i-1][j-1]; pref[i][j] += MOD; pref[i][j] %= MOD; continue; } ll siz = nums[j] - nums[j-1]; ans[i][j] = siz; ans[i][j] += siz * pref[i-1][j-1]; ans[i][j] %= MOD; int g = 1; for(int k = i-1; k > 0; k--) { if(a[k] <= nums[j-1] && nums[j] <= b[k]) { g++; ans[i][j] += (binom(siz+1, g) - (siz+1) + MOD) * (1 + pref[k-1][j-1]); ans[i][j] %= MOD; } } pref[i][j] = ans[i][j] + pref[i][j-1] + pref[i-1][j] - pref[i-1][j-1]; pref[i][j] += MOD; pref[i][j] %= MOD; } } cout << pref[n][nums.size()-1] << endl; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:68:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for(int j = 1; j < nums.size(); j++) {
      |                        ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...