Submission #981168

#TimeUsernameProblemLanguageResultExecution timeMemory
981168hmm789Boat (APIO16_boat)C++14
9 / 100
380 ms8360 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define MOD 1000000007 int pwr(int x, int n) { if(n == 0) return 1; if(n == 1) return x; int h = pwr(x, n/2); if(n%2 == 0) return h*h%MOD; else return h*h%MOD*x%MOD; } int inv2(int x) { return pwr(x, MOD-2); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; // regions [l, r) vector<pair<int, int>> v; vector<int> len; int a[n+1], b[n+1], inv[n+1], ans = 0; for(int i = 1; i <= n; i++) inv[i] = inv2(i); for(int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; v.push_back({a[i], i}); v.push_back({b[i]+1, i+n}); } v.push_back({0, 0}); sort(v.begin(), v.end()); int cnt = 0; for(int i = 0; i < v.size(); i++) { if(v[i].second <= n) a[v[i].second] = cnt; else b[v[i].second-n] = cnt-1; if(i != v.size()-1 && v[i].first != v[i+1].first) { len.push_back(v[i+1].first-v[i].first); cnt++; } } int dp[n+1][v.size()], pref[n+1][v.size()]; memset(dp, 0, sizeof(dp)); memset(pref, 0, sizeof(pref)); dp[0][0] = 1; for(int i = 0; i < v.size(); i++) pref[0][i] = 1; for(int i = 1; i <= n; i++) { for(int j = 1; j < v.size(); j++) { if(j >= a[i] && j <= b[i]) { int c = 1; for(int k = i-1; k >= 0; k--) { c = c*(len[j]+i-k-1)%MOD * inv[i-k]%MOD; dp[i][j] += pref[k][j-1] * c % MOD; dp[i][j] %= MOD; } } pref[i][j] = pref[i][j-1]+dp[i][j]; ans = (ans+dp[i][j]) % MOD; } } cout << ans; }

Compilation message (stderr)

boat.cpp: In function 'int32_t main()':
boat.cpp:37:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i = 0; i < v.size(); i++) {
      |                 ~~^~~~~~~~~~
boat.cpp:40:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   if(i != v.size()-1 && v[i].first != v[i+1].first) {
      |      ~~^~~~~~~~~~~~~
boat.cpp:49:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for(int i = 0; i < v.size(); i++) pref[0][i] = 1;
      |                 ~~^~~~~~~~~~
boat.cpp:51:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int j = 1; j < v.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...