# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1023492 |
2024-07-14T20:43:01 Z |
hackermub |
Boat (APIO16_boat) |
C++17 |
|
2000 ms |
4052 KB |
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define pii pair<int,int>
#define vvi vector<vector<int>>
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define bruh cout<<"\nbruh\n"; exit(0);
#ifndef debug
#define debug(...)
#endif
const int MOD = 1e9 + 7;
int add(int a, int b){
int ans = (a % MOD + b % MOD) % MOD;
while(ans < 0) ans += MOD;
return ans;
}
int mul(int a, int b){
int ans = (a % MOD * b % MOD) % MOD;
while(ans < 0) ans += MOD;
return ans;
}
// a^-1 = binpow(a, MOD - 2);
int binpow(int b, int p){
int ans = 1;
b %= MOD;
while(p > 0){
if(p & 1) ans = mul(ans, b);
b = mul(b, b);
p /= 2;
}
return ans;
}
int compress(vector<pii>& v){
vector<int> val;
for(auto [a, b] : v){
if(!a) continue;
val.push_back(a);
val.push_back(b);
}
sort(all(val));
val.erase(unique(all(val)), val.end());
for(auto& [a, b] : v){
if(!a) continue;
a = lower_bound(all(val), a) - val.begin() + 1;
b = lower_bound(all(val), b) - val.begin() + 1;
}
return sz(val);
}
void solve(){
int n;
cin >> n;
vector<pii> v(n + 1);
for(int i = 1; i <= n; i++){
cin >> v[i].first >> v[i].second;
}
int MX = compress(v);
// debug(v, MX);
int dp[n + 1][MX + 1];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for(int i = 1; i <= n; i++){
for(int j = v[i].first; j <= v[i].second; j++){
for(int k = 0; k < i; k++){
for(int l = v[k].first; l <= min(j - 1, v[k].second); l++){
dp[i][j] = add(dp[i][j], dp[k][l]);
// debug(i, j, dp[i][j]);
}
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = v[i].first; j <= v[i].second; j++){
ans = add(ans, dp[i][j]);
}
}
cout << ans << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie();
int T = 1;
// cin>>T;
for(int ti = 1; ti <= T; ti++){
// cout<< "Case "<<ti<<":\n";
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
3 |
Correct |
3 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2368 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2212 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
3 ms |
2252 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
3 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
3 |
Correct |
3 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2368 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2212 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
3 ms |
2252 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
3 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Execution timed out |
2077 ms |
4052 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
94 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
3 |
Correct |
3 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2368 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2212 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
3 ms |
2252 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
3 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Execution timed out |
2077 ms |
4052 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |