# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
723251 |
2023-04-13T12:36:35 Z |
n0sk1ll |
Boat (APIO16_boat) |
C++14 |
|
547 ms |
464 KB |
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)
using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;
//Note to self: Check for overflow
int inv[2005];
int power(int a, int n)
{
li c=1;
while (n)
{
if (n&1) (c*=a)%=mod;
a=(li)a*a%mod,n>>=1;
}
return c;
}
int a[505],b[505];
int dp[505];
int main()
{
FAST;
int n; cin>>n;
fff(i,1,n) cin>>a[i]>>b[i];
vector<int> kords;
kords.pb(0);
kords.pb(mod);
fff(i,1,n) kords.pb(a[i]);
fff(i,1,n) kords.pb(b[i]+1);
sort(all(kords));
kords.erase(unique(all(kords)),kords.end());
dp[0]=1;
fff(i,1,2000) inv[i]=power(i,mod-2);
inv[0]=1;
ff(k,1,(int)kords.size()-1)
{
bfff(i,1,n) if (a[i]<=kords[k] && kords[k]<=b[i])
{
li binom=1,gore=kords[k+1]-kords[k],dole=0;
bfff(f,1,i)
{
if (a[f]<=kords[k] && kords[k]<=b[f])
{
(binom*=(gore++))%=mod;
(binom*=(inv[++dole]))%=mod;
}
(dp[i]+=(li)dp[f-1]*binom%mod)%=mod;
}
}
//cout<<kords[k]<<": ";
//fff(i,1,n) cout<<dp[i]<<" "; cout<<endl;
}
int ans=0;
fff(i,1,n) (ans+=dp[i])%=mod;
cout<<ans<<"\n";
}
//Note to self: Check for overflow
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
244 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
244 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
252 ms |
464 KB |
Output is correct |
22 |
Correct |
246 ms |
340 KB |
Output is correct |
23 |
Correct |
222 ms |
336 KB |
Output is correct |
24 |
Correct |
232 ms |
340 KB |
Output is correct |
25 |
Correct |
265 ms |
336 KB |
Output is correct |
26 |
Correct |
455 ms |
340 KB |
Output is correct |
27 |
Correct |
469 ms |
340 KB |
Output is correct |
28 |
Correct |
484 ms |
340 KB |
Output is correct |
29 |
Correct |
451 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
3 ms |
356 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
352 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
4 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
4 ms |
340 KB |
Output is correct |
38 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
324 KB |
Output is correct |
6 |
Correct |
5 ms |
212 KB |
Output is correct |
7 |
Correct |
5 ms |
212 KB |
Output is correct |
8 |
Correct |
5 ms |
340 KB |
Output is correct |
9 |
Correct |
6 ms |
336 KB |
Output is correct |
10 |
Correct |
6 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
212 KB |
Output is correct |
14 |
Correct |
3 ms |
212 KB |
Output is correct |
15 |
Correct |
4 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
244 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
252 ms |
464 KB |
Output is correct |
22 |
Correct |
246 ms |
340 KB |
Output is correct |
23 |
Correct |
222 ms |
336 KB |
Output is correct |
24 |
Correct |
232 ms |
340 KB |
Output is correct |
25 |
Correct |
265 ms |
336 KB |
Output is correct |
26 |
Correct |
455 ms |
340 KB |
Output is correct |
27 |
Correct |
469 ms |
340 KB |
Output is correct |
28 |
Correct |
484 ms |
340 KB |
Output is correct |
29 |
Correct |
451 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
3 ms |
356 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
352 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
4 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
4 ms |
340 KB |
Output is correct |
38 |
Correct |
4 ms |
340 KB |
Output is correct |
39 |
Correct |
3 ms |
212 KB |
Output is correct |
40 |
Correct |
3 ms |
332 KB |
Output is correct |
41 |
Correct |
4 ms |
340 KB |
Output is correct |
42 |
Correct |
4 ms |
340 KB |
Output is correct |
43 |
Correct |
3 ms |
324 KB |
Output is correct |
44 |
Correct |
5 ms |
212 KB |
Output is correct |
45 |
Correct |
5 ms |
212 KB |
Output is correct |
46 |
Correct |
5 ms |
340 KB |
Output is correct |
47 |
Correct |
6 ms |
336 KB |
Output is correct |
48 |
Correct |
6 ms |
340 KB |
Output is correct |
49 |
Correct |
4 ms |
332 KB |
Output is correct |
50 |
Correct |
2 ms |
340 KB |
Output is correct |
51 |
Correct |
3 ms |
212 KB |
Output is correct |
52 |
Correct |
3 ms |
212 KB |
Output is correct |
53 |
Correct |
4 ms |
332 KB |
Output is correct |
54 |
Correct |
2 ms |
212 KB |
Output is correct |
55 |
Correct |
2 ms |
332 KB |
Output is correct |
56 |
Correct |
2 ms |
212 KB |
Output is correct |
57 |
Correct |
2 ms |
340 KB |
Output is correct |
58 |
Correct |
2 ms |
212 KB |
Output is correct |
59 |
Correct |
272 ms |
340 KB |
Output is correct |
60 |
Correct |
254 ms |
340 KB |
Output is correct |
61 |
Correct |
242 ms |
460 KB |
Output is correct |
62 |
Correct |
295 ms |
340 KB |
Output is correct |
63 |
Correct |
249 ms |
340 KB |
Output is correct |
64 |
Correct |
547 ms |
340 KB |
Output is correct |
65 |
Correct |
533 ms |
340 KB |
Output is correct |
66 |
Correct |
546 ms |
340 KB |
Output is correct |
67 |
Correct |
533 ms |
340 KB |
Output is correct |
68 |
Correct |
536 ms |
340 KB |
Output is correct |
69 |
Correct |
228 ms |
340 KB |
Output is correct |
70 |
Correct |
235 ms |
340 KB |
Output is correct |
71 |
Correct |
216 ms |
340 KB |
Output is correct |
72 |
Correct |
245 ms |
340 KB |
Output is correct |
73 |
Correct |
232 ms |
340 KB |
Output is correct |
74 |
Correct |
51 ms |
340 KB |
Output is correct |
75 |
Correct |
59 ms |
332 KB |
Output is correct |
76 |
Correct |
58 ms |
340 KB |
Output is correct |
77 |
Correct |
56 ms |
340 KB |
Output is correct |
78 |
Correct |
58 ms |
340 KB |
Output is correct |