Submission #96008

# Submission time Handle Problem Language Result Execution time Memory
96008 2019-02-05T07:32:46 Z oolimry Boat (APIO16_boat) C++14
9 / 100
2000 ms 8316 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;
        }

        for(int j = 0;j < m;j++){

            if(a[i] <= ranges[j].first && b[i] >= ranges[j].second){
                long long acc = 0ll;
                acc += diff[j];
                for(int l = 0;l < j;l++){
                    acc += dp[i-1][l];
                    acc %= mod;
                }
                acc *= diff[j];
                acc %= mod;
                dp[i][j] += acc;
                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++){
                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 6392 KB Output is correct
2 Correct 16 ms 6392 KB Output is correct
3 Correct 16 ms 6264 KB Output is correct
4 Correct 16 ms 6392 KB Output is correct
5 Correct 16 ms 6392 KB Output is correct
6 Correct 16 ms 6400 KB Output is correct
7 Correct 16 ms 6264 KB Output is correct
8 Correct 17 ms 6264 KB Output is correct
9 Correct 15 ms 6264 KB Output is correct
10 Correct 17 ms 6264 KB Output is correct
11 Correct 16 ms 6392 KB Output is correct
12 Correct 16 ms 6264 KB Output is correct
13 Correct 17 ms 6392 KB Output is correct
14 Correct 16 ms 6264 KB Output is correct
15 Correct 16 ms 6392 KB Output is correct
16 Correct 5 ms 3064 KB Output is correct
17 Correct 6 ms 3192 KB Output is correct
18 Correct 6 ms 3064 KB Output is correct
19 Correct 5 ms 3064 KB Output is correct
20 Correct 5 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 6392 KB Output is correct
2 Correct 16 ms 6392 KB Output is correct
3 Correct 16 ms 6264 KB Output is correct
4 Correct 16 ms 6392 KB Output is correct
5 Correct 16 ms 6392 KB Output is correct
6 Correct 16 ms 6400 KB Output is correct
7 Correct 16 ms 6264 KB Output is correct
8 Correct 17 ms 6264 KB Output is correct
9 Correct 15 ms 6264 KB Output is correct
10 Correct 17 ms 6264 KB Output is correct
11 Correct 16 ms 6392 KB Output is correct
12 Correct 16 ms 6264 KB Output is correct
13 Correct 17 ms 6392 KB Output is correct
14 Correct 16 ms 6264 KB Output is correct
15 Correct 16 ms 6392 KB Output is correct
16 Correct 5 ms 3064 KB Output is correct
17 Correct 6 ms 3192 KB Output is correct
18 Correct 6 ms 3064 KB Output is correct
19 Correct 5 ms 3064 KB Output is correct
20 Correct 5 ms 3064 KB Output is correct
21 Execution timed out 2053 ms 8316 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 6392 KB Output is correct
2 Correct 16 ms 6392 KB Output is correct
3 Correct 16 ms 6264 KB Output is correct
4 Correct 16 ms 6392 KB Output is correct
5 Correct 16 ms 6392 KB Output is correct
6 Correct 16 ms 6400 KB Output is correct
7 Correct 16 ms 6264 KB Output is correct
8 Correct 17 ms 6264 KB Output is correct
9 Correct 15 ms 6264 KB Output is correct
10 Correct 17 ms 6264 KB Output is correct
11 Correct 16 ms 6392 KB Output is correct
12 Correct 16 ms 6264 KB Output is correct
13 Correct 17 ms 6392 KB Output is correct
14 Correct 16 ms 6264 KB Output is correct
15 Correct 16 ms 6392 KB Output is correct
16 Correct 5 ms 3064 KB Output is correct
17 Correct 6 ms 3192 KB Output is correct
18 Correct 6 ms 3064 KB Output is correct
19 Correct 5 ms 3064 KB Output is correct
20 Correct 5 ms 3064 KB Output is correct
21 Execution timed out 2053 ms 8316 KB Time limit exceeded
22 Halted 0 ms 0 KB -