이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |