Submission #448068

# Submission time Handle Problem Language Result Execution time Memory
448068 2021-07-28T17:11:42 Z urd05 Boat (APIO16_boat) C++17
100 / 100
496 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> press;
int n;
typedef pair<int,int> P;
P arr[501];
long long psum[501];
long long save[501];
const int mod=1e9+7;
long long value[501];

long long fastpow(long long a,long long b) {
    if (b==0) {
        return 1;
    }
    if (b%2==1) {
        return (fastpow(a,b-1)*a)%mod;
    }
    long long half=fastpow(a,b/2);
    return (half*half)%mod;
}

int main(void) {
    scanf("%d",&n);
    press.push_back(1);
    for(int i=1;i<=n;i++) {
        int a,b;
        scanf("%d %d",&a,&b);
        arr[i]=P(a,b);
        press.push_back(a);
        press.push_back(b+1);
    }
    sort(press.begin(),press.end());
    press.erase(unique(press.begin(),press.end()),press.end());
    for(int i=1;i<=n;i++) {
        arr[i].first=lower_bound(press.begin(),press.end(),arr[i].first)-press.begin()+1;
        arr[i].second=lower_bound(press.begin(),press.end(),arr[i].second+1)-press.begin();
    }
    for(int i=0;i<n;i++) {
        psum[i]=1;
    }
    for(int i=1;i<press.size();i++) {
        int sz=press[i]-press[i-1];
        value[0]=sz;
        for(int j=1;j<=n;j++) {
            value[j]=(value[j-1]*(sz+j))%mod;
            value[j]*=fastpow(j+1,mod-2);
            value[j]%=mod;
        }
        vector<long long> v;
        save[0]=0;
        for(int j=1;j<=n;j++) {
            if (arr[j].first<=i&&i<=arr[j].second) {
                v.insert(v.begin(),psum[j-1]);
            }
            save[j]=0;
            for(int k=0;k<v.size();k++) {
                save[j]+=(value[k]*v[k])%mod;
                save[j]%=mod;
            }
        }
        for(int j=0;j<=n;j++) {
            //printf("%lld ",save[j]);
            psum[j]+=save[j];
            psum[j]%=mod;
        }
        //printf("\n");
    }
    printf("%lld",psum[n]);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=1;i<press.size();i++) {
      |                 ~^~~~~~~~~~~~~
boat.cpp:58:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             for(int k=0;k<v.size();k++) {
      |                         ~^~~~~~~~~
boat.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
boat.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 149 ms 292 KB Output is correct
2 Correct 149 ms 204 KB Output is correct
3 Correct 151 ms 300 KB Output is correct
4 Correct 149 ms 204 KB Output is correct
5 Correct 150 ms 288 KB Output is correct
6 Correct 147 ms 300 KB Output is correct
7 Correct 148 ms 292 KB Output is correct
8 Correct 150 ms 204 KB Output is correct
9 Correct 160 ms 204 KB Output is correct
10 Correct 150 ms 292 KB Output is correct
11 Correct 147 ms 204 KB Output is correct
12 Correct 149 ms 204 KB Output is correct
13 Correct 147 ms 292 KB Output is correct
14 Correct 149 ms 292 KB Output is correct
15 Correct 150 ms 288 KB Output is correct
16 Correct 28 ms 308 KB Output is correct
17 Correct 29 ms 288 KB Output is correct
18 Correct 29 ms 296 KB Output is correct
19 Correct 29 ms 204 KB Output is correct
20 Correct 30 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 292 KB Output is correct
2 Correct 149 ms 204 KB Output is correct
3 Correct 151 ms 300 KB Output is correct
4 Correct 149 ms 204 KB Output is correct
5 Correct 150 ms 288 KB Output is correct
6 Correct 147 ms 300 KB Output is correct
7 Correct 148 ms 292 KB Output is correct
8 Correct 150 ms 204 KB Output is correct
9 Correct 160 ms 204 KB Output is correct
10 Correct 150 ms 292 KB Output is correct
11 Correct 147 ms 204 KB Output is correct
12 Correct 149 ms 204 KB Output is correct
13 Correct 147 ms 292 KB Output is correct
14 Correct 149 ms 292 KB Output is correct
15 Correct 150 ms 288 KB Output is correct
16 Correct 28 ms 308 KB Output is correct
17 Correct 29 ms 288 KB Output is correct
18 Correct 29 ms 296 KB Output is correct
19 Correct 29 ms 204 KB Output is correct
20 Correct 30 ms 204 KB Output is correct
21 Correct 323 ms 308 KB Output is correct
22 Correct 334 ms 308 KB Output is correct
23 Correct 311 ms 304 KB Output is correct
24 Correct 331 ms 300 KB Output is correct
25 Correct 341 ms 204 KB Output is correct
26 Correct 414 ms 304 KB Output is correct
27 Correct 413 ms 300 KB Output is correct
28 Correct 410 ms 304 KB Output is correct
29 Correct 400 ms 300 KB Output is correct
30 Correct 156 ms 324 KB Output is correct
31 Correct 148 ms 312 KB Output is correct
32 Correct 150 ms 312 KB Output is correct
33 Correct 162 ms 324 KB Output is correct
34 Correct 148 ms 320 KB Output is correct
35 Correct 150 ms 204 KB Output is correct
36 Correct 151 ms 304 KB Output is correct
37 Correct 152 ms 300 KB Output is correct
38 Correct 152 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 204 KB Output is correct
2 Correct 9 ms 204 KB Output is correct
3 Correct 8 ms 204 KB Output is correct
4 Correct 8 ms 204 KB Output is correct
5 Correct 8 ms 204 KB Output is correct
6 Correct 9 ms 312 KB Output is correct
7 Correct 10 ms 204 KB Output is correct
8 Correct 9 ms 204 KB Output is correct
9 Correct 9 ms 312 KB Output is correct
10 Correct 11 ms 332 KB Output is correct
11 Correct 9 ms 308 KB Output is correct
12 Correct 8 ms 308 KB Output is correct
13 Correct 10 ms 204 KB Output is correct
14 Correct 8 ms 204 KB Output is correct
15 Correct 8 ms 204 KB Output is correct
16 Correct 5 ms 204 KB Output is correct
17 Correct 5 ms 204 KB Output is correct
18 Correct 5 ms 308 KB Output is correct
19 Correct 6 ms 300 KB Output is correct
20 Correct 5 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 292 KB Output is correct
2 Correct 149 ms 204 KB Output is correct
3 Correct 151 ms 300 KB Output is correct
4 Correct 149 ms 204 KB Output is correct
5 Correct 150 ms 288 KB Output is correct
6 Correct 147 ms 300 KB Output is correct
7 Correct 148 ms 292 KB Output is correct
8 Correct 150 ms 204 KB Output is correct
9 Correct 160 ms 204 KB Output is correct
10 Correct 150 ms 292 KB Output is correct
11 Correct 147 ms 204 KB Output is correct
12 Correct 149 ms 204 KB Output is correct
13 Correct 147 ms 292 KB Output is correct
14 Correct 149 ms 292 KB Output is correct
15 Correct 150 ms 288 KB Output is correct
16 Correct 28 ms 308 KB Output is correct
17 Correct 29 ms 288 KB Output is correct
18 Correct 29 ms 296 KB Output is correct
19 Correct 29 ms 204 KB Output is correct
20 Correct 30 ms 204 KB Output is correct
21 Correct 323 ms 308 KB Output is correct
22 Correct 334 ms 308 KB Output is correct
23 Correct 311 ms 304 KB Output is correct
24 Correct 331 ms 300 KB Output is correct
25 Correct 341 ms 204 KB Output is correct
26 Correct 414 ms 304 KB Output is correct
27 Correct 413 ms 300 KB Output is correct
28 Correct 410 ms 304 KB Output is correct
29 Correct 400 ms 300 KB Output is correct
30 Correct 156 ms 324 KB Output is correct
31 Correct 148 ms 312 KB Output is correct
32 Correct 150 ms 312 KB Output is correct
33 Correct 162 ms 324 KB Output is correct
34 Correct 148 ms 320 KB Output is correct
35 Correct 150 ms 204 KB Output is correct
36 Correct 151 ms 304 KB Output is correct
37 Correct 152 ms 300 KB Output is correct
38 Correct 152 ms 300 KB Output is correct
39 Correct 8 ms 204 KB Output is correct
40 Correct 9 ms 204 KB Output is correct
41 Correct 8 ms 204 KB Output is correct
42 Correct 8 ms 204 KB Output is correct
43 Correct 8 ms 204 KB Output is correct
44 Correct 9 ms 312 KB Output is correct
45 Correct 10 ms 204 KB Output is correct
46 Correct 9 ms 204 KB Output is correct
47 Correct 9 ms 312 KB Output is correct
48 Correct 11 ms 332 KB Output is correct
49 Correct 9 ms 308 KB Output is correct
50 Correct 8 ms 308 KB Output is correct
51 Correct 10 ms 204 KB Output is correct
52 Correct 8 ms 204 KB Output is correct
53 Correct 8 ms 204 KB Output is correct
54 Correct 5 ms 204 KB Output is correct
55 Correct 5 ms 204 KB Output is correct
56 Correct 5 ms 308 KB Output is correct
57 Correct 6 ms 300 KB Output is correct
58 Correct 5 ms 204 KB Output is correct
59 Correct 372 ms 308 KB Output is correct
60 Correct 351 ms 204 KB Output is correct
61 Correct 350 ms 204 KB Output is correct
62 Correct 374 ms 312 KB Output is correct
63 Correct 355 ms 304 KB Output is correct
64 Correct 462 ms 204 KB Output is correct
65 Correct 496 ms 308 KB Output is correct
66 Correct 463 ms 204 KB Output is correct
67 Correct 491 ms 324 KB Output is correct
68 Correct 474 ms 204 KB Output is correct
69 Correct 373 ms 304 KB Output is correct
70 Correct 384 ms 204 KB Output is correct
71 Correct 389 ms 300 KB Output is correct
72 Correct 390 ms 308 KB Output is correct
73 Correct 399 ms 324 KB Output is correct
74 Correct 77 ms 204 KB Output is correct
75 Correct 72 ms 204 KB Output is correct
76 Correct 70 ms 304 KB Output is correct
77 Correct 68 ms 204 KB Output is correct
78 Correct 67 ms 304 KB Output is correct