Submission #25201

#TimeUsernameProblemLanguageResultExecution timeMemory
25201gabrielsimoesBoat (APIO16_boat)C++14
100 / 100
179 ms2048 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1000000007; const int MAXN = 501; const int MAX = 1e6+10; #define mod(a, b) (((a)*(b)) % MOD) ll invpow(ll a, ll b = MOD-2) { ll ret = 1; ll prod = a; for (int i = 0; i <= 30; i++) { if ((1LL << i) & b) ret = (ret * prod) % MOD; prod = (prod*prod) % MOD; } return ret; } int n; ll a[MAXN], b[MAXN]; vector<ll> v; ll inv[MAXN], c[MAXN]; ll dp[MAXN], sum[MAXN]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld %lld", &a[i], &b[i]); b[i]++; v.push_back(a[i]); v.push_back(b[i]); } sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); for (int i = 1; i <= n; i++) inv[i] = invpow(i); for (int i = 0; i < n; i++) { a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin(); b[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin(); } for (int region = 1; region < v.size(); region++) { ll L = v[region] - v[region-1]; c[0] = 1; for (int i = 1; i <= n; i++) c[i] = mod(mod(L + i - 2, inv[i]), c[i-1]); c[1] = L; sum[0] = 1; for (int i = 1; i <= n; i++) sum[i] = (dp[i-1] + sum[i-1]) % MOD; for (int i = n-1; i >= 0; i--) { if (region <= a[i] || region > b[i]) continue; for (int k = i, cnt = 0; k >= 0; k--) { if (region <= a[k] || region > b[k]) continue; dp[i] += mod(c[++cnt], sum[k]); } dp[i] %= MOD; } } ll ans = 0; for (int i = 0; i < n; i++) ans += dp[i]; printf("%lld\n", ans % MOD); }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:50:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int region = 1; region < v.size(); region++) {
                              ^
boat.cpp:31:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
boat.cpp:33:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &a[i], &b[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...