답안 #96009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96009 2019-02-05T07:37:06 Z oolimry Boat (APIO16_boat) C++14
9 / 100
33 ms 8312 KB
#include <bits/stdc++.h>

using namespace std;
typedef pair<long long, long long> ii;
long long mod = 1000000007;
//long long dp[505][2005];
int main()
{
    //freopen("i.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    long long a[n];
    long long b[n];
    set<long long> s;
    for(int i = 0;i < n;i++){
        cin >> a[i] >> b[i];
        s.insert(a[i]);
        s.insert(b[i]);
    }
    //cout << s.size() << endl;
    vector<long long> k;
    for(set<long long>::iterator it = s.begin();it != s.end();it++){
        k.push_back(*it);
    }
    //cout << k.size() << endl;
    vector<ii> ranges;
    for(int i = 0;i < k.size();i++){
        ranges.push_back(ii(k[i],k[i]));
        if(i != 0){
            if(k[i] != k[i-1]+1){
                ranges.push_back(ii(k[i-1]+1,k[i]-1));
            }
        }
    }
    sort(ranges.begin(),ranges.end());
    int m = ranges.size();
    //cout << m << "\n";
    long long diff[m];
    for(int i = 0;i < m;i++){
        diff[i] = ranges[i].second - ranges[i].first + 1;
        //cout << ranges[i].first << " " << ranges[i].second << "\n";
    }



    static long long dp[505][2005];

    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            dp[i][j] = 0ll;
        }
    }

    for(int j = 0;j < m;j++){
        if(a[0] <= ranges[j].first && b[0] >= ranges[j].second){
            dp[0][j] = diff[j];
        }
    }
    for(int i = 1;i < n;i++){
        ///take nothing for this school
        for(int j = 0;j < m;j++){
            dp[i][j] += dp[i-1][j];
            dp[i][j] %= mod;
        }
        long long acc = 0ll;
        for(int j = 0;j < m;j++){
            if(j != 0) acc += dp[i-1][j-1];
            acc %= mod;
            if(a[i] <= ranges[j].first && b[i] >= ranges[j].second){
                long long x = acc;
                x += 1;
                x *= diff[j];
                acc %= mod;
                dp[i][j] += x;
                dp[i][j] %= mod;
            }
        }
    }
/*
    for(int j = 0;j < m;j++){
        cout << ranges[j].first << " " << ranges[j].second << ": ";
        for(int i = 0;i < n;i++){
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }
    */
    long long ans = 0ll;
    for(int j = 0;j < m;j++){
        ans  += dp[n-1][j];
        ans %= mod;
    }
    cout << ans;

    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:28:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i < k.size();i++){
                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 6264 KB Output is correct
2 Correct 18 ms 6392 KB Output is correct
3 Correct 18 ms 6264 KB Output is correct
4 Correct 18 ms 6364 KB Output is correct
5 Correct 20 ms 6264 KB Output is correct
6 Correct 19 ms 6264 KB Output is correct
7 Correct 18 ms 6264 KB Output is correct
8 Correct 20 ms 6392 KB Output is correct
9 Correct 19 ms 6392 KB Output is correct
10 Correct 20 ms 6264 KB Output is correct
11 Correct 27 ms 6392 KB Output is correct
12 Correct 18 ms 6264 KB Output is correct
13 Correct 18 ms 6264 KB Output is correct
14 Correct 20 ms 6392 KB Output is correct
15 Correct 19 ms 6264 KB Output is correct
16 Correct 6 ms 3064 KB Output is correct
17 Correct 7 ms 3064 KB Output is correct
18 Correct 6 ms 3064 KB Output is correct
19 Correct 6 ms 3064 KB Output is correct
20 Correct 7 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 6264 KB Output is correct
2 Correct 18 ms 6392 KB Output is correct
3 Correct 18 ms 6264 KB Output is correct
4 Correct 18 ms 6364 KB Output is correct
5 Correct 20 ms 6264 KB Output is correct
6 Correct 19 ms 6264 KB Output is correct
7 Correct 18 ms 6264 KB Output is correct
8 Correct 20 ms 6392 KB Output is correct
9 Correct 19 ms 6392 KB Output is correct
10 Correct 20 ms 6264 KB Output is correct
11 Correct 27 ms 6392 KB Output is correct
12 Correct 18 ms 6264 KB Output is correct
13 Correct 18 ms 6264 KB Output is correct
14 Correct 20 ms 6392 KB Output is correct
15 Correct 19 ms 6264 KB Output is correct
16 Correct 6 ms 3064 KB Output is correct
17 Correct 7 ms 3064 KB Output is correct
18 Correct 6 ms 3064 KB Output is correct
19 Correct 6 ms 3064 KB Output is correct
20 Correct 7 ms 3064 KB Output is correct
21 Incorrect 33 ms 8312 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 6264 KB Output is correct
2 Correct 18 ms 6392 KB Output is correct
3 Correct 18 ms 6264 KB Output is correct
4 Correct 18 ms 6364 KB Output is correct
5 Correct 20 ms 6264 KB Output is correct
6 Correct 19 ms 6264 KB Output is correct
7 Correct 18 ms 6264 KB Output is correct
8 Correct 20 ms 6392 KB Output is correct
9 Correct 19 ms 6392 KB Output is correct
10 Correct 20 ms 6264 KB Output is correct
11 Correct 27 ms 6392 KB Output is correct
12 Correct 18 ms 6264 KB Output is correct
13 Correct 18 ms 6264 KB Output is correct
14 Correct 20 ms 6392 KB Output is correct
15 Correct 19 ms 6264 KB Output is correct
16 Correct 6 ms 3064 KB Output is correct
17 Correct 7 ms 3064 KB Output is correct
18 Correct 6 ms 3064 KB Output is correct
19 Correct 6 ms 3064 KB Output is correct
20 Correct 7 ms 3064 KB Output is correct
21 Incorrect 33 ms 8312 KB Output isn't correct
22 Halted 0 ms 0 KB -