Submission #102787

# Submission time Handle Problem Language Result Execution time Memory
102787 2019-03-27T14:07:06 Z CorneliuVadimTudor Boat (APIO16_boat) C++14
58 / 100
2000 ms 8320 KB
#include <bits/stdc++.h>
#define MAXN 1000
#define MAXG 2000

struct Event{
    int time, node, tip;
    bool operator < (const Event &aux) const{
        return time < aux.time;
    }
};
std::vector <Event> V;
std::set <int> S;

const long long MOD = 1000000007;
long long d[1 + MAXG][1 + MAXN];
long long C[1 + MAXN], D[1 + MAXN];

inline long long logPow(long long a, long long n){
    long long p = 1;
    while(n){
        if(n % 2) p = p * a % MOD;
        a = a * a % MOD;
        n /= 2;
    }
    return p;
}

int main(){
    FILE*fi,*fo;
    //fi = fopen("a.in","r");
    //fo = fopen("a.out","w");
    fi = stdin;
    fo = stdout;

    int n;
    fscanf(fi,"%d", &n);
    for(int i = 1; i <= n; i++){
        int a, b;
        fscanf(fi,"%d%d", &a, &b);
        V.push_back({a, i, 1});
        V.push_back({b + 1, i, -1});
    }
    std::sort(V.begin(), V.end());

    int j = 0, group = 0;
    d[group][0] = 1;
    for(int i = 0; i < V.size(); i = j){
        j = i;
        while(j < V.size() && V[j].time == V[i].time){
            if(V[j].tip == 1) S.insert(V[j].node);
            else S.erase(V[j].node);
            j++;
        }
        if(!S.size()) continue;

        int len = V[j].time - V[i].time;
        C[0] = 1;
        for(int p = 1; p <= std::min((int)S.size(), len); p++){
            C[p] = C[p - 1] * (len - p + 1) % MOD;
            C[p] = C[p] * logPow(p, MOD - 2) % MOD;
        }

        for(int x = 0; x <= S.size(); x++){
            long long Cxp = 1;
            D[x] = 0;
            for(int p = 1; p <= std::min(x, len); p++){
                Cxp = Cxp * (x - p + 1) % MOD;
                Cxp = Cxp * logPow(p, MOD - 2) % MOD;
                D[x] = (D[x] + C[p] * Cxp % MOD) % MOD;
            }
        }

        group++;
        for(int prev = 0; prev <= n; prev++){
            auto next = S.begin();
            while(next != S.end() && *next <= prev) next++;

            int x = 0;
            while(next != S.end()){
                x++;
                d[group][*next] = (d[group][*next] + d[group - 1][prev] * D[x]) % MOD;
                next++;
            }
        }

        auto next = S.begin();
        long long prev = d[group][*next];
        next++;
        while(next != S.end()){
            long long aux = d[group][*next];
            d[group][*next] = (d[group][*next] - prev + MOD) % MOD;
            prev = aux;
            next++;
        }

        for(int prev = 0; prev <= n; prev++)
            d[group][prev] = (d[group][prev] + d[group - 1][prev]) % MOD;
    }

    long long ans = 0;
    for(int prev = 1; prev <= n; prev++)
        ans = (ans + d[group][prev]) % MOD;

    fprintf(fo,"%lld", ans);

    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:47:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < V.size(); i = j){
                    ~~^~~~~~~~~~
boat.cpp:49:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(j < V.size() && V[j].time == V[i].time){
               ~~^~~~~~~~~~
boat.cpp:63:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int x = 0; x <= S.size(); x++){
                        ~~^~~~~~~~~~~
boat.cpp:36:11: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fi,"%d", &n);
     ~~~~~~^~~~~~~~~~~~~
boat.cpp:39:15: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf(fi,"%d%d", &a, &b);
         ~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4352 KB Output is correct
2 Correct 8 ms 4224 KB Output is correct
3 Correct 11 ms 4224 KB Output is correct
4 Correct 8 ms 4224 KB Output is correct
5 Correct 12 ms 4316 KB Output is correct
6 Correct 8 ms 4224 KB Output is correct
7 Correct 8 ms 4224 KB Output is correct
8 Correct 8 ms 4224 KB Output is correct
9 Correct 8 ms 4224 KB Output is correct
10 Correct 10 ms 4352 KB Output is correct
11 Correct 9 ms 4224 KB Output is correct
12 Correct 10 ms 4224 KB Output is correct
13 Correct 9 ms 4352 KB Output is correct
14 Correct 9 ms 4252 KB Output is correct
15 Correct 9 ms 4352 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1152 KB Output is correct
18 Correct 5 ms 1152 KB Output is correct
19 Correct 5 ms 1152 KB Output is correct
20 Correct 4 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4352 KB Output is correct
2 Correct 8 ms 4224 KB Output is correct
3 Correct 11 ms 4224 KB Output is correct
4 Correct 8 ms 4224 KB Output is correct
5 Correct 12 ms 4316 KB Output is correct
6 Correct 8 ms 4224 KB Output is correct
7 Correct 8 ms 4224 KB Output is correct
8 Correct 8 ms 4224 KB Output is correct
9 Correct 8 ms 4224 KB Output is correct
10 Correct 10 ms 4352 KB Output is correct
11 Correct 9 ms 4224 KB Output is correct
12 Correct 10 ms 4224 KB Output is correct
13 Correct 9 ms 4352 KB Output is correct
14 Correct 9 ms 4252 KB Output is correct
15 Correct 9 ms 4352 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1152 KB Output is correct
18 Correct 5 ms 1152 KB Output is correct
19 Correct 5 ms 1152 KB Output is correct
20 Correct 4 ms 1024 KB Output is correct
21 Correct 556 ms 7556 KB Output is correct
22 Correct 576 ms 7596 KB Output is correct
23 Correct 536 ms 7424 KB Output is correct
24 Correct 566 ms 7432 KB Output is correct
25 Correct 560 ms 7544 KB Output is correct
26 Correct 797 ms 7388 KB Output is correct
27 Correct 835 ms 7544 KB Output is correct
28 Correct 780 ms 7344 KB Output is correct
29 Correct 762 ms 7200 KB Output is correct
30 Correct 16 ms 8192 KB Output is correct
31 Correct 19 ms 8320 KB Output is correct
32 Correct 18 ms 8192 KB Output is correct
33 Correct 16 ms 8192 KB Output is correct
34 Correct 16 ms 8064 KB Output is correct
35 Correct 15 ms 8192 KB Output is correct
36 Correct 19 ms 8192 KB Output is correct
37 Correct 22 ms 8192 KB Output is correct
38 Correct 21 ms 8056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1308 KB Output is correct
2 Correct 20 ms 1280 KB Output is correct
3 Correct 26 ms 1272 KB Output is correct
4 Correct 29 ms 1364 KB Output is correct
5 Correct 32 ms 1272 KB Output is correct
6 Correct 58 ms 1272 KB Output is correct
7 Correct 57 ms 1272 KB Output is correct
8 Correct 58 ms 1272 KB Output is correct
9 Correct 58 ms 1356 KB Output is correct
10 Correct 59 ms 1272 KB Output is correct
11 Correct 36 ms 1400 KB Output is correct
12 Correct 24 ms 1272 KB Output is correct
13 Correct 26 ms 1256 KB Output is correct
14 Correct 27 ms 1400 KB Output is correct
15 Correct 30 ms 1272 KB Output is correct
16 Correct 16 ms 896 KB Output is correct
17 Correct 13 ms 896 KB Output is correct
18 Correct 15 ms 896 KB Output is correct
19 Correct 13 ms 896 KB Output is correct
20 Correct 18 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4352 KB Output is correct
2 Correct 8 ms 4224 KB Output is correct
3 Correct 11 ms 4224 KB Output is correct
4 Correct 8 ms 4224 KB Output is correct
5 Correct 12 ms 4316 KB Output is correct
6 Correct 8 ms 4224 KB Output is correct
7 Correct 8 ms 4224 KB Output is correct
8 Correct 8 ms 4224 KB Output is correct
9 Correct 8 ms 4224 KB Output is correct
10 Correct 10 ms 4352 KB Output is correct
11 Correct 9 ms 4224 KB Output is correct
12 Correct 10 ms 4224 KB Output is correct
13 Correct 9 ms 4352 KB Output is correct
14 Correct 9 ms 4252 KB Output is correct
15 Correct 9 ms 4352 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1152 KB Output is correct
18 Correct 5 ms 1152 KB Output is correct
19 Correct 5 ms 1152 KB Output is correct
20 Correct 4 ms 1024 KB Output is correct
21 Correct 556 ms 7556 KB Output is correct
22 Correct 576 ms 7596 KB Output is correct
23 Correct 536 ms 7424 KB Output is correct
24 Correct 566 ms 7432 KB Output is correct
25 Correct 560 ms 7544 KB Output is correct
26 Correct 797 ms 7388 KB Output is correct
27 Correct 835 ms 7544 KB Output is correct
28 Correct 780 ms 7344 KB Output is correct
29 Correct 762 ms 7200 KB Output is correct
30 Correct 16 ms 8192 KB Output is correct
31 Correct 19 ms 8320 KB Output is correct
32 Correct 18 ms 8192 KB Output is correct
33 Correct 16 ms 8192 KB Output is correct
34 Correct 16 ms 8064 KB Output is correct
35 Correct 15 ms 8192 KB Output is correct
36 Correct 19 ms 8192 KB Output is correct
37 Correct 22 ms 8192 KB Output is correct
38 Correct 21 ms 8056 KB Output is correct
39 Correct 27 ms 1308 KB Output is correct
40 Correct 20 ms 1280 KB Output is correct
41 Correct 26 ms 1272 KB Output is correct
42 Correct 29 ms 1364 KB Output is correct
43 Correct 32 ms 1272 KB Output is correct
44 Correct 58 ms 1272 KB Output is correct
45 Correct 57 ms 1272 KB Output is correct
46 Correct 58 ms 1272 KB Output is correct
47 Correct 58 ms 1356 KB Output is correct
48 Correct 59 ms 1272 KB Output is correct
49 Correct 36 ms 1400 KB Output is correct
50 Correct 24 ms 1272 KB Output is correct
51 Correct 26 ms 1256 KB Output is correct
52 Correct 27 ms 1400 KB Output is correct
53 Correct 30 ms 1272 KB Output is correct
54 Correct 16 ms 896 KB Output is correct
55 Correct 13 ms 896 KB Output is correct
56 Correct 15 ms 896 KB Output is correct
57 Correct 13 ms 896 KB Output is correct
58 Correct 18 ms 888 KB Output is correct
59 Execution timed out 2033 ms 5128 KB Time limit exceeded
60 Halted 0 ms 0 KB -