Submission #23522

# Submission time Handle Problem Language Result Execution time Memory
23522 2017-05-12T06:32:17 Z zoomswk Boat (APIO16_boat) C++14
9 / 100
6 ms 1244 KB
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

#define MOD 1000000007

int a[2505], b[2505];
vector<int> v;
int arr[2505];
int l[2505], r[2505];
long long dp[2505];

int main(){
    int N;
    scanf("%d", &N);
    for(int i=0; i<N; i++) scanf("%d%d", &a[i], &b[i]), v.push_back(a[i]), v.push_back(b[i]);
    sort(v.begin(), v.end());
    int ptr = 1;
    arr[ptr++] = v[0];
    for(int i=1; i<v.size(); i++) if(v[i] != v[i-1]) arr[ptr++] = v[i];
    int ptr2 = 1;
    if(arr[1] != 1){
        l[ptr2] = 1;
        r[ptr2] = arr[1]-1;
        ptr2++;
    }
    l[ptr2] = arr[1];
    r[ptr2] = arr[1];
    ptr2++;
    for(int i=2; i<ptr; i++){
        if(arr[i-1]+1 <= arr[i]-1){
            l[ptr2] = arr[i-1]+1;
            r[ptr2] = arr[i]-1;
            ptr2++;
        }
        l[ptr2] = arr[i];
        r[ptr2] = arr[i];
        ptr2++;
    }
    for(int i=0; i<N; i++) for(int j=0; j<ptr2; j++){
        if(l[j] == a[i]) a[i] = j;
        if(l[j] == b[i]) b[i] = j;
    }
    dp[0] = 1;
    for(int i=0; i<N; i++){
        long long sum = dp[0];
        for(int j=1; j<ptr2; j++){
            long long tmp = dp[j];
            if(j >= a[i] && j <= b[i]){
                dp[j] += sum;
                dp[j] %= MOD;
            }
            sum += tmp*(r[j]-l[j]+1);
            sum %= MOD;
        }
    }
    long long res = 0;
    for(int i=1; i<ptr2; i++) res += dp[i]*(r[i]-l[i]+1), res %= MOD;
    printf("%lld", res);
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:21:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<v.size(); i++) if(v[i] != v[i-1]) arr[ptr++] = v[i];
                   ^
boat.cpp:16:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
                    ^
boat.cpp:17:93: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0; i<N; i++) scanf("%d%d", &a[i], &b[i]), v.push_back(a[i]), v.push_back(b[i]);
                                                                                             ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1244 KB Output is correct
2 Correct 3 ms 1244 KB Output is correct
3 Correct 3 ms 1244 KB Output is correct
4 Correct 3 ms 1244 KB Output is correct
5 Correct 3 ms 1244 KB Output is correct
6 Correct 3 ms 1244 KB Output is correct
7 Correct 3 ms 1244 KB Output is correct
8 Correct 3 ms 1244 KB Output is correct
9 Correct 3 ms 1244 KB Output is correct
10 Correct 3 ms 1244 KB Output is correct
11 Correct 3 ms 1244 KB Output is correct
12 Correct 3 ms 1244 KB Output is correct
13 Correct 3 ms 1244 KB Output is correct
14 Correct 3 ms 1244 KB Output is correct
15 Correct 3 ms 1244 KB Output is correct
16 Correct 0 ms 1244 KB Output is correct
17 Correct 0 ms 1244 KB Output is correct
18 Correct 0 ms 1244 KB Output is correct
19 Correct 0 ms 1244 KB Output is correct
20 Correct 0 ms 1244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1244 KB Output is correct
2 Correct 3 ms 1244 KB Output is correct
3 Correct 3 ms 1244 KB Output is correct
4 Correct 3 ms 1244 KB Output is correct
5 Correct 3 ms 1244 KB Output is correct
6 Correct 3 ms 1244 KB Output is correct
7 Correct 3 ms 1244 KB Output is correct
8 Correct 3 ms 1244 KB Output is correct
9 Correct 3 ms 1244 KB Output is correct
10 Correct 3 ms 1244 KB Output is correct
11 Correct 3 ms 1244 KB Output is correct
12 Correct 3 ms 1244 KB Output is correct
13 Correct 3 ms 1244 KB Output is correct
14 Correct 3 ms 1244 KB Output is correct
15 Correct 3 ms 1244 KB Output is correct
16 Correct 0 ms 1244 KB Output is correct
17 Correct 0 ms 1244 KB Output is correct
18 Correct 0 ms 1244 KB Output is correct
19 Correct 0 ms 1244 KB Output is correct
20 Correct 0 ms 1244 KB Output is correct
21 Incorrect 6 ms 1244 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1244 KB Output is correct
2 Correct 3 ms 1244 KB Output is correct
3 Correct 3 ms 1244 KB Output is correct
4 Correct 3 ms 1244 KB Output is correct
5 Correct 3 ms 1244 KB Output is correct
6 Correct 3 ms 1244 KB Output is correct
7 Correct 3 ms 1244 KB Output is correct
8 Correct 3 ms 1244 KB Output is correct
9 Correct 3 ms 1244 KB Output is correct
10 Correct 3 ms 1244 KB Output is correct
11 Correct 3 ms 1244 KB Output is correct
12 Correct 3 ms 1244 KB Output is correct
13 Correct 3 ms 1244 KB Output is correct
14 Correct 3 ms 1244 KB Output is correct
15 Correct 3 ms 1244 KB Output is correct
16 Correct 0 ms 1244 KB Output is correct
17 Correct 0 ms 1244 KB Output is correct
18 Correct 0 ms 1244 KB Output is correct
19 Correct 0 ms 1244 KB Output is correct
20 Correct 0 ms 1244 KB Output is correct
21 Incorrect 6 ms 1244 KB Output isn't correct
22 Halted 0 ms 0 KB -