이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define a first
#define b second
using namespace std;
const long long INF = 1e18;
const int MOD = 1e9+7;
int n;
vector < map<int,int> > dp(1000);
vector < pair<int,int> > v(1000);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++)
cin >> v[i].a >> v[i].b;
map<int,int> :: iterator it;
for(int i = 1; i <= n; i++){
for(it = dp[i-1].begin(); it != dp[i-1].end(); it++)
dp[i][it->first] = it->second;
it = dp[i-1].begin();
int x = v[i].a;
int cnt = 0;
while(it != dp[i-1].end()) {
if(it->first >= x) break;
dp[i][x] = (dp[i][x] + it->second) % MOD;
cnt = (cnt + it->second) % MOD;
it++;
}
//if(it != dp[i-1].end())
// it++;
for(int j = v[i].a+1; j <= v[i].b; j++){
dp[i][j] = (dp[i][j] + cnt) % MOD;
if(it != dp[i-1].end() && it->first < j){
dp[i][j] = (dp[i][j] + it->second) % MOD;
cnt = (cnt + it->second) % MOD;
it++;
}
}
for(int j = v[i].a; j <= v[i].b; j++)
dp[i][j] = (dp[i][j]+1) % MOD;
}
it = dp[n].begin();
int ans = 0;
while(it != dp[n].end()) {
ans = (ans+(it->second)) % MOD;
//cout << it->second <<" "<<dp[1][it->first]<< " - " << it->first << endl;
it++;
}
cout << ans;
}
# | 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... |