Submission #448065

# Submission time Handle Problem Language Result Execution time Memory
448065 2021-07-28T17:08:54 Z urd05 Boat (APIO16_boat) C++17
9 / 100
327 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]=1;
        for(int j=1;j<=n;j++) {
            value[j]=(value[j-1]*(sz+j-1))%mod;
            value[j]*=fastpow(j,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 159 ms 332 KB Output is correct
2 Correct 157 ms 316 KB Output is correct
3 Correct 159 ms 304 KB Output is correct
4 Correct 154 ms 304 KB Output is correct
5 Correct 159 ms 304 KB Output is correct
6 Correct 152 ms 304 KB Output is correct
7 Correct 153 ms 308 KB Output is correct
8 Correct 151 ms 300 KB Output is correct
9 Correct 153 ms 300 KB Output is correct
10 Correct 149 ms 204 KB Output is correct
11 Correct 148 ms 312 KB Output is correct
12 Correct 148 ms 304 KB Output is correct
13 Correct 152 ms 304 KB Output is correct
14 Correct 148 ms 300 KB Output is correct
15 Correct 148 ms 304 KB Output is correct
16 Correct 27 ms 204 KB Output is correct
17 Correct 30 ms 204 KB Output is correct
18 Correct 29 ms 316 KB Output is correct
19 Correct 30 ms 324 KB Output is correct
20 Correct 29 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 332 KB Output is correct
2 Correct 157 ms 316 KB Output is correct
3 Correct 159 ms 304 KB Output is correct
4 Correct 154 ms 304 KB Output is correct
5 Correct 159 ms 304 KB Output is correct
6 Correct 152 ms 304 KB Output is correct
7 Correct 153 ms 308 KB Output is correct
8 Correct 151 ms 300 KB Output is correct
9 Correct 153 ms 300 KB Output is correct
10 Correct 149 ms 204 KB Output is correct
11 Correct 148 ms 312 KB Output is correct
12 Correct 148 ms 304 KB Output is correct
13 Correct 152 ms 304 KB Output is correct
14 Correct 148 ms 300 KB Output is correct
15 Correct 148 ms 304 KB Output is correct
16 Correct 27 ms 204 KB Output is correct
17 Correct 30 ms 204 KB Output is correct
18 Correct 29 ms 316 KB Output is correct
19 Correct 30 ms 324 KB Output is correct
20 Correct 29 ms 320 KB Output is correct
21 Incorrect 327 ms 204 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 159 ms 332 KB Output is correct
2 Correct 157 ms 316 KB Output is correct
3 Correct 159 ms 304 KB Output is correct
4 Correct 154 ms 304 KB Output is correct
5 Correct 159 ms 304 KB Output is correct
6 Correct 152 ms 304 KB Output is correct
7 Correct 153 ms 308 KB Output is correct
8 Correct 151 ms 300 KB Output is correct
9 Correct 153 ms 300 KB Output is correct
10 Correct 149 ms 204 KB Output is correct
11 Correct 148 ms 312 KB Output is correct
12 Correct 148 ms 304 KB Output is correct
13 Correct 152 ms 304 KB Output is correct
14 Correct 148 ms 300 KB Output is correct
15 Correct 148 ms 304 KB Output is correct
16 Correct 27 ms 204 KB Output is correct
17 Correct 30 ms 204 KB Output is correct
18 Correct 29 ms 316 KB Output is correct
19 Correct 30 ms 324 KB Output is correct
20 Correct 29 ms 320 KB Output is correct
21 Incorrect 327 ms 204 KB Output isn't correct
22 Halted 0 ms 0 KB -