# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
172681 |
2020-01-02T11:06:12 Z |
Ruxandra985 |
Boat (APIO16_boat) |
C++14 |
|
999 ms |
6600 KB |
#include <bits/stdc++.h>
#define DIMN 510
#define MOD 1000000007
using namespace std;
pair <long long,long long> v[DIMN] , tot[2*DIMN];
long long dp[2*DIMN][DIMN] , op[DIMN] , last[DIMN] , fact[DIMN];
long long sum[DIMN][DIMN] , inv[DIMN];
void combinari (long long x , long long y){
last[0] = 1;
for (long long i = 1 ; i <= y && i <= x ; i++)
last[i] = ((long long)last[i-1] * (x - i + 1)) % MOD;
}
long long ridput (long long x , long long y){
long long sol = 1;
while (y){
if (y % 2)
sol = ((long long) sol * x )%MOD;
x = ((long long) x * x )%MOD;
y/=2;
}
return sol;
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
long long n , elem , open , i , j , k , left , toput;
fscanf (fin,"%lld",&n);
elem = 0;
fact[0] = 1;
inv[0] = 1;
for (i=1;i<=n;i++){
fscanf (fin,"%lld%lld",&v[i].first,&v[i].second);
tot[++elem] = make_pair(v[i].first , i);
tot[++elem] = make_pair(v[i].second + 1 , -i);
fact[i] = ((long long) fact[i-1] * i )%MOD;
inv[i] = ridput(fact[i] , MOD-2);
}
tot[++elem] = make_pair(1000000001 , 0);
sort (tot + 1 , tot + elem + 1);
dp[0][0] = 1;
open = 0;
int ant = 0;
for (i=1;i<elem;i++){
dp[i][0] = 1;
/// vreau sa pun cateva in intervalul tot[i].first ... tot[i+1].first - 1
if (tot[i].second > 0){ /// incepe ceva
for (j = open + 1 ; ; j--){
if (op[j-1] > tot[i].second)
op[j] = op[j-1];
else {
op[j] = tot[i].second;
break;
}
}
open++;
}
else { /// s a terminat ceva
for (j = 1 ; j<open ; j++){
if (op[j+1] > -tot[i].second)
op[j] = op[j+1];
}
op[open] = 0;
open--;
}
if (tot[i+1].first == tot[i].first)
continue;
combinari (tot[i+1].first - tot[i].first , open);
for (j=1;j<=open;j++){
for (k=1;k<=j;k++){ /// sa pui k dintre j in interval
sum[j][k] = (sum[j][k-1] + ( (last[k] * inv[k])%MOD
*( ( (fact[j-1] * inv[k-1] )%MOD * inv[j-k])%MOD)%MOD )%MOD )%MOD;
}
}
for (j=1;j<=n;j++)
dp[i][j] = dp[ant][j];
/// ai updatat lista de disponibile
for (j = 1 ; j <= open ; j++){ /// cea mai mare pe care o pun sigur
left = j;
for (k = 0 ; k <= op[j] ; k++){
while (left && k >= op[j - left + 1]) /// sunt o(n) overall
left--;
/// in interv curant pui cv subset intre opant[k] si op[j]
/// pe k esti 100% sigura ca l ai pus
toput = min(tot[i+1].first - tot[i].first , left);
if (!toput)
break;
/// poti sa pui intre 1 si toput in intervalul asta
/// stii ca tu vrei neaparat sa il pui pe op[j]
dp[i][op[j]] += ( dp[ant][k] * sum[left][toput] )%MOD;
dp[i][op[j]] %= MOD;
}
}
ant = i;
}
long long sol = 0;
for (i=1;i<=n;i++)
sol = (sol + dp[elem - 1][i])%MOD;
fprintf (fout,"%lld",sol);
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:36:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%lld",&n);
~~~~~~~^~~~~~~~~~~~~~~
boat.cpp:41:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%lld%lld",&v[i].first,&v[i].second);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4344 KB |
Output is correct |
2 |
Correct |
7 ms |
4344 KB |
Output is correct |
3 |
Correct |
7 ms |
4216 KB |
Output is correct |
4 |
Correct |
7 ms |
4344 KB |
Output is correct |
5 |
Correct |
7 ms |
4344 KB |
Output is correct |
6 |
Correct |
7 ms |
4344 KB |
Output is correct |
7 |
Correct |
8 ms |
4344 KB |
Output is correct |
8 |
Correct |
7 ms |
4348 KB |
Output is correct |
9 |
Correct |
7 ms |
4348 KB |
Output is correct |
10 |
Correct |
7 ms |
4344 KB |
Output is correct |
11 |
Correct |
7 ms |
4344 KB |
Output is correct |
12 |
Correct |
7 ms |
4348 KB |
Output is correct |
13 |
Correct |
7 ms |
4344 KB |
Output is correct |
14 |
Correct |
7 ms |
4344 KB |
Output is correct |
15 |
Correct |
7 ms |
4344 KB |
Output is correct |
16 |
Correct |
7 ms |
4472 KB |
Output is correct |
17 |
Correct |
7 ms |
4516 KB |
Output is correct |
18 |
Correct |
6 ms |
4472 KB |
Output is correct |
19 |
Correct |
7 ms |
4472 KB |
Output is correct |
20 |
Correct |
7 ms |
4472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4344 KB |
Output is correct |
2 |
Correct |
7 ms |
4344 KB |
Output is correct |
3 |
Correct |
7 ms |
4216 KB |
Output is correct |
4 |
Correct |
7 ms |
4344 KB |
Output is correct |
5 |
Correct |
7 ms |
4344 KB |
Output is correct |
6 |
Correct |
7 ms |
4344 KB |
Output is correct |
7 |
Correct |
8 ms |
4344 KB |
Output is correct |
8 |
Correct |
7 ms |
4348 KB |
Output is correct |
9 |
Correct |
7 ms |
4348 KB |
Output is correct |
10 |
Correct |
7 ms |
4344 KB |
Output is correct |
11 |
Correct |
7 ms |
4344 KB |
Output is correct |
12 |
Correct |
7 ms |
4348 KB |
Output is correct |
13 |
Correct |
7 ms |
4344 KB |
Output is correct |
14 |
Correct |
7 ms |
4344 KB |
Output is correct |
15 |
Correct |
7 ms |
4344 KB |
Output is correct |
16 |
Correct |
7 ms |
4472 KB |
Output is correct |
17 |
Correct |
7 ms |
4516 KB |
Output is correct |
18 |
Correct |
6 ms |
4472 KB |
Output is correct |
19 |
Correct |
7 ms |
4472 KB |
Output is correct |
20 |
Correct |
7 ms |
4472 KB |
Output is correct |
21 |
Correct |
505 ms |
5476 KB |
Output is correct |
22 |
Correct |
491 ms |
5628 KB |
Output is correct |
23 |
Correct |
443 ms |
5464 KB |
Output is correct |
24 |
Correct |
487 ms |
5504 KB |
Output is correct |
25 |
Correct |
486 ms |
5496 KB |
Output is correct |
26 |
Correct |
853 ms |
6428 KB |
Output is correct |
27 |
Correct |
885 ms |
6504 KB |
Output is correct |
28 |
Correct |
859 ms |
6452 KB |
Output is correct |
29 |
Correct |
848 ms |
6312 KB |
Output is correct |
30 |
Correct |
10 ms |
4472 KB |
Output is correct |
31 |
Correct |
11 ms |
4600 KB |
Output is correct |
32 |
Correct |
9 ms |
4344 KB |
Output is correct |
33 |
Correct |
9 ms |
4344 KB |
Output is correct |
34 |
Correct |
10 ms |
4344 KB |
Output is correct |
35 |
Correct |
9 ms |
4344 KB |
Output is correct |
36 |
Correct |
9 ms |
4344 KB |
Output is correct |
37 |
Correct |
9 ms |
4344 KB |
Output is correct |
38 |
Correct |
9 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1400 KB |
Output is correct |
2 |
Correct |
7 ms |
1400 KB |
Output is correct |
3 |
Correct |
15 ms |
1404 KB |
Output is correct |
4 |
Correct |
7 ms |
1400 KB |
Output is correct |
5 |
Correct |
8 ms |
1528 KB |
Output is correct |
6 |
Correct |
11 ms |
1528 KB |
Output is correct |
7 |
Correct |
11 ms |
1528 KB |
Output is correct |
8 |
Correct |
12 ms |
1528 KB |
Output is correct |
9 |
Correct |
12 ms |
1528 KB |
Output is correct |
10 |
Correct |
11 ms |
1528 KB |
Output is correct |
11 |
Correct |
7 ms |
1400 KB |
Output is correct |
12 |
Correct |
6 ms |
1400 KB |
Output is correct |
13 |
Correct |
5 ms |
1400 KB |
Output is correct |
14 |
Correct |
7 ms |
1400 KB |
Output is correct |
15 |
Correct |
8 ms |
1400 KB |
Output is correct |
16 |
Correct |
6 ms |
1400 KB |
Output is correct |
17 |
Correct |
6 ms |
1400 KB |
Output is correct |
18 |
Correct |
5 ms |
1400 KB |
Output is correct |
19 |
Correct |
6 ms |
1404 KB |
Output is correct |
20 |
Correct |
5 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4344 KB |
Output is correct |
2 |
Correct |
7 ms |
4344 KB |
Output is correct |
3 |
Correct |
7 ms |
4216 KB |
Output is correct |
4 |
Correct |
7 ms |
4344 KB |
Output is correct |
5 |
Correct |
7 ms |
4344 KB |
Output is correct |
6 |
Correct |
7 ms |
4344 KB |
Output is correct |
7 |
Correct |
8 ms |
4344 KB |
Output is correct |
8 |
Correct |
7 ms |
4348 KB |
Output is correct |
9 |
Correct |
7 ms |
4348 KB |
Output is correct |
10 |
Correct |
7 ms |
4344 KB |
Output is correct |
11 |
Correct |
7 ms |
4344 KB |
Output is correct |
12 |
Correct |
7 ms |
4348 KB |
Output is correct |
13 |
Correct |
7 ms |
4344 KB |
Output is correct |
14 |
Correct |
7 ms |
4344 KB |
Output is correct |
15 |
Correct |
7 ms |
4344 KB |
Output is correct |
16 |
Correct |
7 ms |
4472 KB |
Output is correct |
17 |
Correct |
7 ms |
4516 KB |
Output is correct |
18 |
Correct |
6 ms |
4472 KB |
Output is correct |
19 |
Correct |
7 ms |
4472 KB |
Output is correct |
20 |
Correct |
7 ms |
4472 KB |
Output is correct |
21 |
Correct |
505 ms |
5476 KB |
Output is correct |
22 |
Correct |
491 ms |
5628 KB |
Output is correct |
23 |
Correct |
443 ms |
5464 KB |
Output is correct |
24 |
Correct |
487 ms |
5504 KB |
Output is correct |
25 |
Correct |
486 ms |
5496 KB |
Output is correct |
26 |
Correct |
853 ms |
6428 KB |
Output is correct |
27 |
Correct |
885 ms |
6504 KB |
Output is correct |
28 |
Correct |
859 ms |
6452 KB |
Output is correct |
29 |
Correct |
848 ms |
6312 KB |
Output is correct |
30 |
Correct |
10 ms |
4472 KB |
Output is correct |
31 |
Correct |
11 ms |
4600 KB |
Output is correct |
32 |
Correct |
9 ms |
4344 KB |
Output is correct |
33 |
Correct |
9 ms |
4344 KB |
Output is correct |
34 |
Correct |
10 ms |
4344 KB |
Output is correct |
35 |
Correct |
9 ms |
4344 KB |
Output is correct |
36 |
Correct |
9 ms |
4344 KB |
Output is correct |
37 |
Correct |
9 ms |
4344 KB |
Output is correct |
38 |
Correct |
9 ms |
4344 KB |
Output is correct |
39 |
Correct |
7 ms |
1400 KB |
Output is correct |
40 |
Correct |
7 ms |
1400 KB |
Output is correct |
41 |
Correct |
15 ms |
1404 KB |
Output is correct |
42 |
Correct |
7 ms |
1400 KB |
Output is correct |
43 |
Correct |
8 ms |
1528 KB |
Output is correct |
44 |
Correct |
11 ms |
1528 KB |
Output is correct |
45 |
Correct |
11 ms |
1528 KB |
Output is correct |
46 |
Correct |
12 ms |
1528 KB |
Output is correct |
47 |
Correct |
12 ms |
1528 KB |
Output is correct |
48 |
Correct |
11 ms |
1528 KB |
Output is correct |
49 |
Correct |
7 ms |
1400 KB |
Output is correct |
50 |
Correct |
6 ms |
1400 KB |
Output is correct |
51 |
Correct |
5 ms |
1400 KB |
Output is correct |
52 |
Correct |
7 ms |
1400 KB |
Output is correct |
53 |
Correct |
8 ms |
1400 KB |
Output is correct |
54 |
Correct |
6 ms |
1400 KB |
Output is correct |
55 |
Correct |
6 ms |
1400 KB |
Output is correct |
56 |
Correct |
5 ms |
1400 KB |
Output is correct |
57 |
Correct |
6 ms |
1404 KB |
Output is correct |
58 |
Correct |
5 ms |
1400 KB |
Output is correct |
59 |
Correct |
555 ms |
5460 KB |
Output is correct |
60 |
Correct |
522 ms |
5404 KB |
Output is correct |
61 |
Correct |
488 ms |
5496 KB |
Output is correct |
62 |
Correct |
557 ms |
5588 KB |
Output is correct |
63 |
Correct |
540 ms |
5496 KB |
Output is correct |
64 |
Correct |
986 ms |
6600 KB |
Output is correct |
65 |
Correct |
999 ms |
6520 KB |
Output is correct |
66 |
Correct |
994 ms |
6408 KB |
Output is correct |
67 |
Correct |
990 ms |
6432 KB |
Output is correct |
68 |
Correct |
990 ms |
6384 KB |
Output is correct |
69 |
Correct |
441 ms |
5360 KB |
Output is correct |
70 |
Correct |
441 ms |
5368 KB |
Output is correct |
71 |
Correct |
437 ms |
5496 KB |
Output is correct |
72 |
Correct |
458 ms |
5352 KB |
Output is correct |
73 |
Correct |
466 ms |
5284 KB |
Output is correct |
74 |
Correct |
114 ms |
5444 KB |
Output is correct |
75 |
Correct |
106 ms |
5432 KB |
Output is correct |
76 |
Correct |
114 ms |
5412 KB |
Output is correct |
77 |
Correct |
113 ms |
5428 KB |
Output is correct |
78 |
Correct |
116 ms |
5472 KB |
Output is correct |