답안 #109126

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109126 2019-05-04T13:47:15 Z fedoseevtimofey Boat (APIO16_boat) C++14
0 / 100
965 ms 525312 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const int md = 1e9 + 7;
 
void add(int &a, int b) {
    a += b;
    if (a >= md) a -= md;
}
 
int sub(int a, int b) {
    a -= b;
    if (a < 0) a += md;
    return a;
}
 
int mul(int a, int b) {
    return ((ll)a * b) % md;
}
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    vector <int> a(n), b(n);
    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
    vector <int> c;
    for (int i = 0; i < n; ++i) {
        c.push_back(a[i]); 
        c.push_back(b[i]);
        c.push_back(a[i] - 1);
        c.push_back(b[i] - 1);
    }
    for (int i = 0; i < (int)1e6; ++i) c.push_back(i);
    c.push_back(0);
    sort(c.begin(), c.end());
    c.resize(unique(c.begin(), c.end()) - c.begin());
    for (int i = 0; i < n; ++i) {
        a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin();
        b[i] = lower_bound(c.begin(), c.end(), b[i]) - c.begin();
    }
    int m = c.size();
    vector <vector <int>> dp(n + 1, vector <int> (m + 1));
    for (int j = 0; j <= m; ++j) dp[0][j] = 1;
 
    for (int i = 1; i <= n; ++i) {
        int l = a[i - 1];
        int r = b[i - 1];
        dp[i][0] = dp[i - 1][0];
        for (int j = 1; j <= m; ++j) {
            add(dp[i][j], dp[i][j - 1]);
            add(dp[i][j], sub(dp[i - 1][j], dp[i - 1][j - 1]));
            if (l <= j && j <= r) {
                add(dp[i][j], mul(sub(c[j], c[j - 1]), dp[i - 1][j - 1]));
            }
        }
    }
    cout << sub(dp[n][m], 1) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 965 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 965 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 879 ms 403856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 965 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -