# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
342008 | 2021-01-01T02:31:24 Z | thecodingwizard | Boat (APIO16_boat) | C++11 | 9 ms | 8300 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ii pair<int, int> #define f first #define s second #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define F0R(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define inf 1000000010 #define int ll const int mod = 1e9+7; int32_t main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; ii A[n]; map<int, int> compress; set<int> setValues; setValues.insert(0); setValues.insert(1); F0R(i, n) { cin >> A[i].f >> A[i].s; A[i].s++; setValues.insert(A[i].f); setValues.insert(A[i].s); } int idx = 0; vector<int> values; for (auto x : setValues) { compress[x] = idx; values.pb(x); idx++; } F0R(i, n) { A[i].f = compress[A[i].f]; A[i].s = compress[A[i].s]; } int dp[n][values.size()]; int dpSum[n][values.size()]; F0R(i, n) { F0R(j, values.size()-1) { if (i == 0 && j == 0) { dp[i][j] = 1; continue; } if (A[i].f <= j && A[i].s > j) { // range is within [a...b] ll numValues = values[j+1]-values[j]; dp[i][j] = ((ll)(i==0?0:dp[i-1][j]) + (ll)(i>0&&j>0?dpSum[i-1][j-1]:1)*numValues) % mod; } else { // range is outside of [a...b] dp[i][j] = i==0?0:dp[i-1][j]; } if (j == 0) assert(dp[i][j] == 1); //cout << "dp[" << i << "][" << j << "]: " << dp[i][j] << endl; } F0R(j, values.size()-1) { dpSum[i][j] = ((ll)(j>0?dpSum[i][j-1]:0)+dp[i][j])%mod; } } cout << dpSum[n-1][values.size()-2]-1 << endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 8300 KB | Output is correct |
2 | Correct | 9 ms | 8300 KB | Output is correct |
3 | Correct | 9 ms | 8300 KB | Output is correct |
4 | Correct | 9 ms | 8300 KB | Output is correct |
5 | Correct | 9 ms | 8300 KB | Output is correct |
6 | Correct | 9 ms | 8300 KB | Output is correct |
7 | Correct | 9 ms | 8300 KB | Output is correct |
8 | Correct | 9 ms | 8300 KB | Output is correct |
9 | Correct | 9 ms | 8300 KB | Output is correct |
10 | Correct | 9 ms | 8300 KB | Output is correct |
11 | Correct | 9 ms | 8300 KB | Output is correct |
12 | Correct | 9 ms | 8300 KB | Output is correct |
13 | Correct | 9 ms | 8300 KB | Output is correct |
14 | Correct | 9 ms | 8300 KB | Output is correct |
15 | Correct | 9 ms | 8300 KB | Output is correct |
16 | Correct | 2 ms | 1772 KB | Output is correct |
17 | Correct | 2 ms | 1900 KB | Output is correct |
18 | Correct | 2 ms | 1772 KB | Output is correct |
19 | Correct | 2 ms | 1848 KB | Output is correct |
20 | Correct | 2 ms | 1772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 8300 KB | Output is correct |
2 | Correct | 9 ms | 8300 KB | Output is correct |
3 | Correct | 9 ms | 8300 KB | Output is correct |
4 | Correct | 9 ms | 8300 KB | Output is correct |
5 | Correct | 9 ms | 8300 KB | Output is correct |
6 | Correct | 9 ms | 8300 KB | Output is correct |
7 | Correct | 9 ms | 8300 KB | Output is correct |
8 | Correct | 9 ms | 8300 KB | Output is correct |
9 | Correct | 9 ms | 8300 KB | Output is correct |
10 | Correct | 9 ms | 8300 KB | Output is correct |
11 | Correct | 9 ms | 8300 KB | Output is correct |
12 | Correct | 9 ms | 8300 KB | Output is correct |
13 | Correct | 9 ms | 8300 KB | Output is correct |
14 | Correct | 9 ms | 8300 KB | Output is correct |
15 | Correct | 9 ms | 8300 KB | Output is correct |
16 | Correct | 2 ms | 1772 KB | Output is correct |
17 | Correct | 2 ms | 1900 KB | Output is correct |
18 | Correct | 2 ms | 1772 KB | Output is correct |
19 | Correct | 2 ms | 1848 KB | Output is correct |
20 | Correct | 2 ms | 1772 KB | Output is correct |
21 | Incorrect | 9 ms | 7660 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 620 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 8300 KB | Output is correct |
2 | Correct | 9 ms | 8300 KB | Output is correct |
3 | Correct | 9 ms | 8300 KB | Output is correct |
4 | Correct | 9 ms | 8300 KB | Output is correct |
5 | Correct | 9 ms | 8300 KB | Output is correct |
6 | Correct | 9 ms | 8300 KB | Output is correct |
7 | Correct | 9 ms | 8300 KB | Output is correct |
8 | Correct | 9 ms | 8300 KB | Output is correct |
9 | Correct | 9 ms | 8300 KB | Output is correct |
10 | Correct | 9 ms | 8300 KB | Output is correct |
11 | Correct | 9 ms | 8300 KB | Output is correct |
12 | Correct | 9 ms | 8300 KB | Output is correct |
13 | Correct | 9 ms | 8300 KB | Output is correct |
14 | Correct | 9 ms | 8300 KB | Output is correct |
15 | Correct | 9 ms | 8300 KB | Output is correct |
16 | Correct | 2 ms | 1772 KB | Output is correct |
17 | Correct | 2 ms | 1900 KB | Output is correct |
18 | Correct | 2 ms | 1772 KB | Output is correct |
19 | Correct | 2 ms | 1848 KB | Output is correct |
20 | Correct | 2 ms | 1772 KB | Output is correct |
21 | Incorrect | 9 ms | 7660 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |