Submission #518472

# Submission time Handle Problem Language Result Execution time Memory
518472 2022-01-23T21:26:31 Z julian33 Boat (APIO16_boat) C++14
9 / 100
900 ms 4468 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cerr<<vars<<" = ";
    string delim="";
    (...,(cerr<<delim<<values,delim=", "));
    cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif

#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);} 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mxN=2e5+5; //make sure this is right
const int mod=1e9+7;

struct RANK{
    vector<int> all;
    int get(int x){return lower_bound(all.begin(),all.end(),x)-all.begin()+1;}
    void add(int x){all.pb(x);}
    void fix(){
        sort(all.begin(),all.end());
        all.resize(unique(all.begin(),all.end())-all.begin());
    }  
} rnk;

ll dp[505][1005],a[505],b[505];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    rnk.add(1);
    int n; cin>>n;
    int mx=0;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        rnk.add(a[i]);
        rnk.add(b[i]);
        maxa(mx,(int)b[i]);
    }
    rnk.add(mx+1);
    rnk.fix();
    dp[0][1]=1;
    for(int i=1;i<=n;i++){
        int A=a[i]; int B=b[i];
        for(int j=1;j<=sz(rnk.all);j++){
            ll ways=min(B,rnk.all[j-1]-1)-max(A,j==1?1:rnk.all[j-2])+1;
            maxa(ways,0LL);
            dp[i][j]=dp[i-1][j];
            for(int k=j-1;k>=1;k--){
                dp[i][j]+=(dp[i-1][k]*ways)%mod;
                dp[i][j]%=mod;
            }
        }
    }
    ll ans=0;
    for(int i=1;i<=sz(rnk.all);i++)
        ans=(ans+dp[n][i])%mod;
    cout<<(ans-1+mod)%mod<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 266 ms 4208 KB Output is correct
2 Correct 266 ms 4156 KB Output is correct
3 Correct 268 ms 4220 KB Output is correct
4 Correct 272 ms 4208 KB Output is correct
5 Correct 271 ms 4148 KB Output is correct
6 Correct 276 ms 4260 KB Output is correct
7 Correct 267 ms 4468 KB Output is correct
8 Correct 269 ms 4188 KB Output is correct
9 Correct 262 ms 4164 KB Output is correct
10 Correct 270 ms 4212 KB Output is correct
11 Correct 266 ms 4212 KB Output is correct
12 Correct 286 ms 4180 KB Output is correct
13 Correct 266 ms 4208 KB Output is correct
14 Correct 273 ms 4256 KB Output is correct
15 Correct 263 ms 4168 KB Output is correct
16 Correct 10 ms 2648 KB Output is correct
17 Correct 11 ms 2640 KB Output is correct
18 Correct 11 ms 2640 KB Output is correct
19 Correct 13 ms 2640 KB Output is correct
20 Correct 13 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 266 ms 4208 KB Output is correct
2 Correct 266 ms 4156 KB Output is correct
3 Correct 268 ms 4220 KB Output is correct
4 Correct 272 ms 4208 KB Output is correct
5 Correct 271 ms 4148 KB Output is correct
6 Correct 276 ms 4260 KB Output is correct
7 Correct 267 ms 4468 KB Output is correct
8 Correct 269 ms 4188 KB Output is correct
9 Correct 262 ms 4164 KB Output is correct
10 Correct 270 ms 4212 KB Output is correct
11 Correct 266 ms 4212 KB Output is correct
12 Correct 286 ms 4180 KB Output is correct
13 Correct 266 ms 4208 KB Output is correct
14 Correct 273 ms 4256 KB Output is correct
15 Correct 263 ms 4168 KB Output is correct
16 Correct 10 ms 2648 KB Output is correct
17 Correct 11 ms 2640 KB Output is correct
18 Correct 11 ms 2640 KB Output is correct
19 Correct 13 ms 2640 KB Output is correct
20 Correct 13 ms 2640 KB Output is correct
21 Incorrect 900 ms 4348 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 266 ms 4208 KB Output is correct
2 Correct 266 ms 4156 KB Output is correct
3 Correct 268 ms 4220 KB Output is correct
4 Correct 272 ms 4208 KB Output is correct
5 Correct 271 ms 4148 KB Output is correct
6 Correct 276 ms 4260 KB Output is correct
7 Correct 267 ms 4468 KB Output is correct
8 Correct 269 ms 4188 KB Output is correct
9 Correct 262 ms 4164 KB Output is correct
10 Correct 270 ms 4212 KB Output is correct
11 Correct 266 ms 4212 KB Output is correct
12 Correct 286 ms 4180 KB Output is correct
13 Correct 266 ms 4208 KB Output is correct
14 Correct 273 ms 4256 KB Output is correct
15 Correct 263 ms 4168 KB Output is correct
16 Correct 10 ms 2648 KB Output is correct
17 Correct 11 ms 2640 KB Output is correct
18 Correct 11 ms 2640 KB Output is correct
19 Correct 13 ms 2640 KB Output is correct
20 Correct 13 ms 2640 KB Output is correct
21 Incorrect 900 ms 4348 KB Output isn't correct
22 Halted 0 ms 0 KB -