이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
#define int long long
template <class _T>
bool chmin(_T &x, const _T &y){
bool flag = false;
if ( x > y ){
x = y; flag |= true;
}
return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
bool flag = false;
if ( x < y ){
x = y; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector <int> a(n), b(n), pos;
for ( int i = 0; i < n; i++ ){
cin >> a[i] >> b[i];
pos.pb(a[i]); pos.pb(b[i]);
}
sort(all(pos));
pos.resize(unique(all(pos)) - pos.begin());
auto id = [&](int x){
return lower_bound(all(pos), x) - pos.begin() + 1;
};
const int Mod = 1e9 + 7;
auto add = [&](int &x, const int &y){
x = (x + y) % Mod;
if ( x < 0 ) x += Mod;
};
vector <vector<int>> dp(n + 1, vector <int> (n + 1));
dp[0][0] = 1;
for ( int i = 1; i <= n; i++ ){
int v = id(a[i - 1]);
for ( int j = 0; j <= n; j++ ){
dp[i][j] = dp[i - 1][j];
}
for ( int k = 0; k < v; k++ ){
add(dp[i][v], dp[i - 1][k]);
}
}
int cnt = 0;
for ( int i = 1; i <= n; i++ ){
add(cnt, dp[n][i]);
}
cout << cnt;
cout << '\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... |