# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
417868 |
2021-06-04T12:44:01 Z |
erfanmir |
Boat (APIO16_boat) |
C++17 |
|
10 ms |
4304 KB |
// In the name of god
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template < class T > using ordered_set = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(),(x).end()
#define lc(x) (x) << 1
#define rc(x) (x) << 1 | 1
#define F first
#define S second
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define mp make_pair
ll poww(ll a, ll b, ll md) {
ll ans = 1;
for(; b; b >>= 1, a = a * a % md){
if(b & 1){
ans = ans * a % md;
}
}
return ans % md;
}
const int MAXN = 1000 + 10;
const int MAXLG = 18;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;
int n, a[MAXN], b[MAXN];
vector<int> vec;
ll dp[MAXN][MAXN], x[MAXN], ans, inv[MAXN];
int main()
{
scanf("%d", &n);
inv[n] = poww(n, MOD - 2, MOD);
for(int i = n - 1; i >= 0; i--){
inv[i] = (inv[i + 1] * (i + 1)) % MOD;
}
for(int i = 1; i <= n; i++){
scanf("%d %d", a + i, b + i);
b[i]++;
vec.push_back(b[i]);
vec.push_back(a[i]);
}
sort(all(vec));
vec.erase(unique(all(vec)), vec.end());
for(int i = 1; i < (int)vec.size(); i++){
x[i] = vec[i] - vec[i - 1];
}
for(int i = 1; i <= n; i++){
a[i] = lower_bound(all(vec), a[i]) - vec.begin();
b[i] = lower_bound(all(vec), b[i]) - vec.begin();
}
for(int i = 0; i < (int)vec.size(); i++){
dp[0][i] = 1;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j < (int)vec.size(); j++){
if(!(a[i] < j && b[i] >= j)){
continue;
}
ll tmp = x[j], kmp = x[j], vlc = 1;
for(int k = i - 1; k >= 0; k--){
dp[i][j] += (dp[k][j - 1] * tmp) % MOD;
dp[i][j] %= MOD;
if(a[k] < j && b[k] >= j){
kmp++;
vlc++;
tmp *= (kmp * inv[vlc]) % MOD;
tmp %= MOD;
}
}
//printf(":: %d %d %lld\n", i, j, dp[i][j]);
}
for(int j = 1; j < (int)vec.size();j++){
dp[i][j] += dp[i][j - 1];
dp[i][j] %= MOD;
}
}
for(int i = 1; i <= n; i++){
ans += dp[i][(int)vec.size() - 1];
ans %= MOD;
}
printf("%lld\n", ans);
}
Compilation message
boat.cpp:3: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
3 | #pragma comment(linker, "/stack:200000000")
|
boat.cpp: In function 'int main()':
boat.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
boat.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%d %d", a + i, b + i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4264 KB |
Output is correct |
3 |
Correct |
9 ms |
4280 KB |
Output is correct |
4 |
Correct |
8 ms |
4300 KB |
Output is correct |
5 |
Correct |
10 ms |
4260 KB |
Output is correct |
6 |
Correct |
9 ms |
4300 KB |
Output is correct |
7 |
Correct |
8 ms |
4300 KB |
Output is correct |
8 |
Correct |
7 ms |
4300 KB |
Output is correct |
9 |
Correct |
8 ms |
4304 KB |
Output is correct |
10 |
Correct |
8 ms |
4224 KB |
Output is correct |
11 |
Correct |
8 ms |
4300 KB |
Output is correct |
12 |
Correct |
7 ms |
4260 KB |
Output is correct |
13 |
Correct |
7 ms |
4196 KB |
Output is correct |
14 |
Correct |
7 ms |
4300 KB |
Output is correct |
15 |
Correct |
7 ms |
4192 KB |
Output is correct |
16 |
Incorrect |
4 ms |
3020 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4264 KB |
Output is correct |
3 |
Correct |
9 ms |
4280 KB |
Output is correct |
4 |
Correct |
8 ms |
4300 KB |
Output is correct |
5 |
Correct |
10 ms |
4260 KB |
Output is correct |
6 |
Correct |
9 ms |
4300 KB |
Output is correct |
7 |
Correct |
8 ms |
4300 KB |
Output is correct |
8 |
Correct |
7 ms |
4300 KB |
Output is correct |
9 |
Correct |
8 ms |
4304 KB |
Output is correct |
10 |
Correct |
8 ms |
4224 KB |
Output is correct |
11 |
Correct |
8 ms |
4300 KB |
Output is correct |
12 |
Correct |
7 ms |
4260 KB |
Output is correct |
13 |
Correct |
7 ms |
4196 KB |
Output is correct |
14 |
Correct |
7 ms |
4300 KB |
Output is correct |
15 |
Correct |
7 ms |
4192 KB |
Output is correct |
16 |
Incorrect |
4 ms |
3020 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4264 KB |
Output is correct |
3 |
Correct |
9 ms |
4280 KB |
Output is correct |
4 |
Correct |
8 ms |
4300 KB |
Output is correct |
5 |
Correct |
10 ms |
4260 KB |
Output is correct |
6 |
Correct |
9 ms |
4300 KB |
Output is correct |
7 |
Correct |
8 ms |
4300 KB |
Output is correct |
8 |
Correct |
7 ms |
4300 KB |
Output is correct |
9 |
Correct |
8 ms |
4304 KB |
Output is correct |
10 |
Correct |
8 ms |
4224 KB |
Output is correct |
11 |
Correct |
8 ms |
4300 KB |
Output is correct |
12 |
Correct |
7 ms |
4260 KB |
Output is correct |
13 |
Correct |
7 ms |
4196 KB |
Output is correct |
14 |
Correct |
7 ms |
4300 KB |
Output is correct |
15 |
Correct |
7 ms |
4192 KB |
Output is correct |
16 |
Incorrect |
4 ms |
3020 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |