Submission #166981

#TimeUsernameProblemLanguageResultExecution timeMemory
166981egekabasPort Facility (JOI17_port_facility)C++14
0 / 100
4581 ms1048580 KiB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<int, int>  pii;
typedef pair<ld, ld>  pld;
map<pair<ll, pair<stack<pll>, stack<pll>>>, ll> dp;
map<pair<ll, pair<stack<pll>, stack<pll>>>, ll> calc;
ll n;
pll ar[1000009];
ll mod = 1e9+7;
ll func(ll idx, stack<pll> a, stack<pll> b){
    if(idx >= n)
        return 1;
    if(calc[{idx,{a, b}}])
        return dp[{idx,{a, b}}];
    calc[{idx,{a, b}}] = 1;
    int next = 0;
    auto a1 = a;
    auto b1 = b;
    
    while(a.top().ss < ar[idx].ff){
        a.pop();
        next = 1;
    }
    while(b.top().ss < ar[idx].ff){
        b.pop();
        next = 1;
    }
    if(next){
        return dp[{idx,{a1, b1}}] = func(idx, a, b);
    }
    ll cur = 0;
    if(a.top().ss > ar[idx].ss){
        a.push(ar[idx]);
        cur += func(idx+1, a, b);
        cur %= mod;
        a.pop();
    }
    if(b.top().ss > ar[idx].ss){
        b.push(ar[idx]);
        cur += func(idx+1, a, b);
        cur %= mod;
        b.pop();
    }
    //cout << idx << " " << cur << "\n";
    return dp[{idx, {a, b}}] = cur;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n;
    for(ll i = 0; i < n; ++i)
        cin >> ar[i].ff >> ar[i].ss;
    sort(ar, ar+n);
    stack<pll> tmp;
    tmp.push({0, 1e18}); 
    cout << func(0, tmp, tmp) << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...