Submission #250780

# Submission time Handle Problem Language Result Execution time Memory
250780 2020-07-19T06:33:40 Z hackermub Boat (APIO16_boat) C++17
0 / 100
369 ms 2304 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz(v) (int)v.size()
const int MOD = 998244353;
const int64_t INF = 1e18;

int add(int a,int b){
    return (a+b+MOD)%MOD; 
}

int mul(int a,int b){
    return (1LL*a*b)%MOD;
}

int bigmod(int b,int p){
    if(!p) return 1;
    int x = bigmod(b,p/2);
    x = mul(x,x);
    if(p%2) x = mul(x,b);
    return x;
}

int vag(int a,int b){
    return mul(a,bigmod(b,MOD-2));
}

void getseg(vector<pii> &seg,vector<int> &L,vector<int> &R){
    vector<pii> v;
    for(auto x:L) v.push_back({x,0});
    for(auto x:R) v.push_back({x,1});
    sort(all(v));
    v.erase(unique(all(v)),v.end());
    for(int i=1;i<sz(v);i++){
        if(v[i].second == 1){
            if(v[i-1].second == 0) seg.push_back({v[i-1].fi,v[i].fi});
            else seg.push_back({v[i-1].fi+1,v[i].fi});
        }else if(v[i-1].second == 0){
            seg.push_back({v[i-1].fi,v[i].fi-1});
        }
    }
}

int32_t main(){
    int n;
    cin>>n;
    vector<int> L(n),R(n);
    for(int i=0;i<n;i++){
        cin>>L[i]>>R[i];
    }
    vector<pii> seg={{-1,-1}};
    getseg(seg,L,R);
    //for(auto p:seg) cout<<p.fi<<" "<<p.se<<"\n";
    int dp[n+1][sz(seg)];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int j=0;j<sz(seg)-1;j++){
        for(int i=0;i<=n;i++){
            dp[i][j+1] = add(dp[i][j+1] , dp[i][j]);
            int len = seg[j+1].se - seg[j+1].fi + 1;
            int cnt = 1;
            for(int k=1;i+k<=n;k++){
                if(L[i+k-1]<=seg[j+1].fi && seg[j+1].se>R[i+k-1]) cnt=mul(2,cnt);
                dp[i+k][j+1] = add(dp[i+k][j+1] , mul(dp[i][j] , cnt));
                //cout<<cnt<<endl;
            }
        }
    }
    cout<<dp[n][sz(seg)-1];
    return 0;
}

Compilation message

boat.cpp: In function 'int32_t main()':
boat.cpp:66:17: warning: unused variable 'len' [-Wunused-variable]
             int len = seg[j+1].se - seg[j+1].fi + 1;
                 ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 369 ms 2304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 369 ms 2304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 369 ms 2304 KB Output isn't correct
2 Halted 0 ms 0 KB -