Submission #401956

# Submission time Handle Problem Language Result Execution time Memory
401956 2021-05-11T04:15:02 Z Maqsut_03 Boat (APIO16_boat) C++14
100 / 100
1463 ms 4296 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

vector<int> aux;
array<int, 2> v[505];
ll dp[1005][505], inv[505];

int main()
{
    int n, i, j, e;
    scanf("%d" ,&n);
    aux = {-1};
    inv[1] = 1;
    for(i=2; i<=n; i++)
        inv[i] = (mod - mod / i) * inv[mod % i] % mod;
   
    for(i=1;i<=n;i++)
	{
        scanf("%d%d",&v[i][0],&v[i][1]);
        ++v[i][1];
        aux.push_back(v[i][0]);
        aux.push_back(v[i][1]);
    }
    
	sort(aux.begin(),aux.end());
  //  aux.resize(unique(aux.begin(),aux.end())-aux.begin());
    int m=aux.size();
    for(i=0;i<m;i++) dp[i][0]=1;
    
	for(i=1; i<=n; i++)
	{
        for(j=m-1; j>=1; j--)
            if (v[i][0]<=aux[j-1] && aux[j]<=v[i][1])
			{
                int cnt=aux[j]-aux[j-1];
                for(e=min(cnt,i);e>=1;e--)
                    dp[j][e]=(dp[j][e]+dp[j][e-1]*(cnt-e+1)%mod*inv[e])%mod;
            }
        for(j=1;j<=m;j++)
		{
            dp[j][0]=0;
            for(e=0;e<=n;e++)
                dp[j][0]=(dp[j][0]+dp[j-1][e])%mod;
        }
    }
    printf("%lld\n", (dp[m][0] + mod - 1) % mod);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d" ,&n);
      |     ~~~~~^~~~~~~~~~
boat.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%d%d",&v[i][0],&v[i][1]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1163 ms 4256 KB Output is correct
2 Correct 1172 ms 4252 KB Output is correct
3 Correct 1154 ms 4256 KB Output is correct
4 Correct 1159 ms 4256 KB Output is correct
5 Correct 1155 ms 4260 KB Output is correct
6 Correct 1156 ms 4260 KB Output is correct
7 Correct 1156 ms 4268 KB Output is correct
8 Correct 1157 ms 4292 KB Output is correct
9 Correct 1171 ms 4252 KB Output is correct
10 Correct 1167 ms 4260 KB Output is correct
11 Correct 1151 ms 4256 KB Output is correct
12 Correct 1173 ms 4252 KB Output is correct
13 Correct 1164 ms 4260 KB Output is correct
14 Correct 1152 ms 4272 KB Output is correct
15 Correct 1179 ms 4252 KB Output is correct
16 Correct 1166 ms 4252 KB Output is correct
17 Correct 1152 ms 4256 KB Output is correct
18 Correct 1160 ms 4256 KB Output is correct
19 Correct 1179 ms 4272 KB Output is correct
20 Correct 1164 ms 4260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1163 ms 4256 KB Output is correct
2 Correct 1172 ms 4252 KB Output is correct
3 Correct 1154 ms 4256 KB Output is correct
4 Correct 1159 ms 4256 KB Output is correct
5 Correct 1155 ms 4260 KB Output is correct
6 Correct 1156 ms 4260 KB Output is correct
7 Correct 1156 ms 4268 KB Output is correct
8 Correct 1157 ms 4292 KB Output is correct
9 Correct 1171 ms 4252 KB Output is correct
10 Correct 1167 ms 4260 KB Output is correct
11 Correct 1151 ms 4256 KB Output is correct
12 Correct 1173 ms 4252 KB Output is correct
13 Correct 1164 ms 4260 KB Output is correct
14 Correct 1152 ms 4272 KB Output is correct
15 Correct 1179 ms 4252 KB Output is correct
16 Correct 1166 ms 4252 KB Output is correct
17 Correct 1152 ms 4256 KB Output is correct
18 Correct 1160 ms 4256 KB Output is correct
19 Correct 1179 ms 4272 KB Output is correct
20 Correct 1164 ms 4260 KB Output is correct
21 Correct 1164 ms 4248 KB Output is correct
22 Correct 1173 ms 4292 KB Output is correct
23 Correct 1151 ms 4252 KB Output is correct
24 Correct 1157 ms 4292 KB Output is correct
25 Correct 1168 ms 4256 KB Output is correct
26 Correct 1208 ms 4292 KB Output is correct
27 Correct 1166 ms 4248 KB Output is correct
28 Correct 1168 ms 4256 KB Output is correct
29 Correct 1205 ms 4248 KB Output is correct
30 Correct 1156 ms 4260 KB Output is correct
31 Correct 1202 ms 4256 KB Output is correct
32 Correct 1198 ms 4256 KB Output is correct
33 Correct 1204 ms 4256 KB Output is correct
34 Correct 1156 ms 4256 KB Output is correct
35 Correct 1153 ms 4252 KB Output is correct
36 Correct 1171 ms 4292 KB Output is correct
37 Correct 1172 ms 4260 KB Output is correct
38 Correct 1172 ms 4260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1100 KB Output is correct
2 Correct 12 ms 1104 KB Output is correct
3 Correct 12 ms 1100 KB Output is correct
4 Correct 12 ms 1108 KB Output is correct
5 Correct 12 ms 1116 KB Output is correct
6 Correct 13 ms 1108 KB Output is correct
7 Correct 13 ms 1108 KB Output is correct
8 Correct 13 ms 1104 KB Output is correct
9 Correct 13 ms 1108 KB Output is correct
10 Correct 13 ms 1100 KB Output is correct
11 Correct 12 ms 1108 KB Output is correct
12 Correct 12 ms 1100 KB Output is correct
13 Correct 12 ms 1112 KB Output is correct
14 Correct 12 ms 1108 KB Output is correct
15 Correct 13 ms 1108 KB Output is correct
16 Correct 11 ms 1116 KB Output is correct
17 Correct 12 ms 1112 KB Output is correct
18 Correct 12 ms 1100 KB Output is correct
19 Correct 11 ms 1108 KB Output is correct
20 Correct 12 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1163 ms 4256 KB Output is correct
2 Correct 1172 ms 4252 KB Output is correct
3 Correct 1154 ms 4256 KB Output is correct
4 Correct 1159 ms 4256 KB Output is correct
5 Correct 1155 ms 4260 KB Output is correct
6 Correct 1156 ms 4260 KB Output is correct
7 Correct 1156 ms 4268 KB Output is correct
8 Correct 1157 ms 4292 KB Output is correct
9 Correct 1171 ms 4252 KB Output is correct
10 Correct 1167 ms 4260 KB Output is correct
11 Correct 1151 ms 4256 KB Output is correct
12 Correct 1173 ms 4252 KB Output is correct
13 Correct 1164 ms 4260 KB Output is correct
14 Correct 1152 ms 4272 KB Output is correct
15 Correct 1179 ms 4252 KB Output is correct
16 Correct 1166 ms 4252 KB Output is correct
17 Correct 1152 ms 4256 KB Output is correct
18 Correct 1160 ms 4256 KB Output is correct
19 Correct 1179 ms 4272 KB Output is correct
20 Correct 1164 ms 4260 KB Output is correct
21 Correct 1164 ms 4248 KB Output is correct
22 Correct 1173 ms 4292 KB Output is correct
23 Correct 1151 ms 4252 KB Output is correct
24 Correct 1157 ms 4292 KB Output is correct
25 Correct 1168 ms 4256 KB Output is correct
26 Correct 1208 ms 4292 KB Output is correct
27 Correct 1166 ms 4248 KB Output is correct
28 Correct 1168 ms 4256 KB Output is correct
29 Correct 1205 ms 4248 KB Output is correct
30 Correct 1156 ms 4260 KB Output is correct
31 Correct 1202 ms 4256 KB Output is correct
32 Correct 1198 ms 4256 KB Output is correct
33 Correct 1204 ms 4256 KB Output is correct
34 Correct 1156 ms 4256 KB Output is correct
35 Correct 1153 ms 4252 KB Output is correct
36 Correct 1171 ms 4292 KB Output is correct
37 Correct 1172 ms 4260 KB Output is correct
38 Correct 1172 ms 4260 KB Output is correct
39 Correct 12 ms 1100 KB Output is correct
40 Correct 12 ms 1104 KB Output is correct
41 Correct 12 ms 1100 KB Output is correct
42 Correct 12 ms 1108 KB Output is correct
43 Correct 12 ms 1116 KB Output is correct
44 Correct 13 ms 1108 KB Output is correct
45 Correct 13 ms 1108 KB Output is correct
46 Correct 13 ms 1104 KB Output is correct
47 Correct 13 ms 1108 KB Output is correct
48 Correct 13 ms 1100 KB Output is correct
49 Correct 12 ms 1108 KB Output is correct
50 Correct 12 ms 1100 KB Output is correct
51 Correct 12 ms 1112 KB Output is correct
52 Correct 12 ms 1108 KB Output is correct
53 Correct 13 ms 1108 KB Output is correct
54 Correct 11 ms 1116 KB Output is correct
55 Correct 12 ms 1112 KB Output is correct
56 Correct 12 ms 1100 KB Output is correct
57 Correct 11 ms 1108 KB Output is correct
58 Correct 12 ms 1100 KB Output is correct
59 Correct 1369 ms 4252 KB Output is correct
60 Correct 1362 ms 4260 KB Output is correct
61 Correct 1342 ms 4256 KB Output is correct
62 Correct 1362 ms 4256 KB Output is correct
63 Correct 1355 ms 4256 KB Output is correct
64 Correct 1463 ms 4256 KB Output is correct
65 Correct 1442 ms 4252 KB Output is correct
66 Correct 1460 ms 4276 KB Output is correct
67 Correct 1446 ms 4256 KB Output is correct
68 Correct 1459 ms 4296 KB Output is correct
69 Correct 1301 ms 4256 KB Output is correct
70 Correct 1312 ms 4252 KB Output is correct
71 Correct 1296 ms 4252 KB Output is correct
72 Correct 1323 ms 4252 KB Output is correct
73 Correct 1321 ms 4172 KB Output is correct
74 Correct 1178 ms 4252 KB Output is correct
75 Correct 1175 ms 4256 KB Output is correct
76 Correct 1173 ms 4260 KB Output is correct
77 Correct 1173 ms 4256 KB Output is correct
78 Correct 1165 ms 4256 KB Output is correct