Submission #730008

#TimeUsernameProblemLanguageResultExecution timeMemory
730008nguyentunglamBoat (APIO16_boat)C++17
100 / 100
494 ms4428 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 510, mod = 1e9 + 7; int l[N], r[N], a[N], b[N], cnt[N << 1], inv[N], f[2][N << 1][N]; int power(int a, int p) { if (!p) return 1; int tmp = power(a, p >> 1); tmp = 1LL * tmp * tmp % mod; if (p % 2) return 1LL * tmp * a % mod; return tmp; } void add(int &a, int b) { a += b; if (a >= mod) a -= mod; } int main() { cin.tie(0) -> sync_with_stdio(0); int n; cin >> n; vector<int> rrh; for(int i = 1; i <= n; i++) { cin >> l[i] >> r[i]; rrh.push_back(l[i] - 1); rrh.push_back(r[i]); } sort(rrh.begin(), rrh.end()); rrh.resize(unique(rrh.begin(), rrh.end()) - rrh.begin()); for(int i = 1; i <= n; i++) { a[i] = upper_bound(rrh.begin(), rrh.end(), l[i] - 1) - rrh.begin(); b[i] = upper_bound(rrh.begin(), rrh.end(), r[i]) - rrh.begin(); // cout << a[i] << " " << b[i] << endl; } for(int i = 1; i < rrh.size(); i++) cnt[i + 1] = rrh[i] - rrh[i - 1]; // for(int i = 1; i <= rrh.size(); i++) cout << cnt[i] << " "; for(int i = 2; i <= n; i++) inv[i] = power(i, mod - 2); int m = rrh.size(); bool cur = 1; for(int i = 1; i <= n; i++) { bool pre = cur; cur ^= 1; for(int j = 1; j <= m; j++) for(int k = 0; k <= i; k++) f[cur][j][k] = f[pre][j][k]; int prefix = 1; for(int j = 1; j <= a[i]; j++) for(int k = 0; k <= min(cnt[j], i); k++) add(prefix, f[pre][j][k]); for(int j = a[i] + 1; j <= b[i]; j++) { add(f[cur][j][1], 1LL * prefix * cnt[j] % mod); add(prefix, f[pre][j][1]); for(int k = 2; k <= i; k++) { add(f[cur][j][k], 1LL * f[pre][j][k - 1] * (cnt[j] - k + 1) % mod * inv[k] % mod); add(prefix, f[pre][j][k]); } } } int res = 0; for(int j = 2; j <= m; j++) for(int k = 1; k <= n; k++) { add(res, f[cur][j][k]); } cout << res; }

Compilation message (stderr)

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