Submission #986078

# Submission time Handle Problem Language Result Execution time Memory
986078 2024-05-19T17:42:24 Z salmon Boat (APIO16_boat) C++14
100 / 100
725 ms 1892 KB
#include <bits/stdc++.h>
using namespace std;

int N;
pair<int,int> lst[510];
int a, b;
long long int mod = 1'000'000'007;
long long int p[510];
long long int fact[510];
vector<int> de;
vector<int> bat[1100];
map<int,int> mep;

long long int expo(long long int x, long long int b, long long int mul){
    if(mul == 0) return x;
    if(mul % 2 == 1){
        return expo(x * b % mod, b * b % mod, mul / 2);
    }
    else{
        return expo(x, b * b % mod, mul / 2);
    }
}

int main(){

    scanf(" %d",&N);

    for(int i = 1; i <= N; i++){
        scanf(" %d",&a);
        scanf(" %d",&b);

        lst[i] = {a,b};

        de.push_back(a);
        de.push_back(b + 1);
        p[i] = 0;
    }

    p[N + 1] = 0;
    p[0] = 1;

    fact[0] = 1;
    for(int i = 1; i < 510; i++){
        fact[i] = fact[i - 1] *  i % mod;
    }

    sort(de.begin(),de.end());
    de.resize(unique(de.begin(),de.end()) - de.begin());

    for(int i = 0; i < de.size(); i++){
        mep[de[i]] = i;
    }

    for(int i = 1; i <= N; i++){
        for(int j = 0; j < de.size(); j++){
            if(lst[i].first <= de[j] && de[j] <= lst[i].second){
                bat[j].push_back(i);
            }
        }
    }

    for(int i = 0; i < de.size() - 1; i++){
        long long int mul[510];

        int c = de[i + 1] - de[i];

        mul[0] = c;

        for(int i = 1; i < 509; i++){
            mul[i] = mul[i - 1] * (i + c) % mod;
        }

        for(int i = 0; i < 509; i++){
            mul[i] = expo(mul[i], fact[i + 1], mod - 2);
            //printf("%lld ",mul[i]);
        }

        vector<int> v = {0};
        long long int pst[510];

        for(int i = 0; i <= 501; i++){
            pst[i] = 0;
        }

        for(int j = 0; j < bat[i].size(); j++){
            v.push_back(bat[i][j]);
            long long int sum = 0;

            for(int k = 0; k < v.size() - 1; k++){
                int ni = v.size();


                for(int i = v[ni - 2 - k]; i <= v[ni - 1 - k] - 1; i++){
                    sum = (sum + p[i] * mul[k]) % mod;
                }
            }

            pst[bat[i][j]] = sum;
        }

        for(int i = 0; i <= 501; i++){
            p[i] = (p[i] + pst[i]) % mod;
        }
    }

    long long int ans = 0;

    for(int i = 1; i <= N; i++){
        ans = (ans + p[i]) % mod;
    }


    printf("%lld",ans);
}
/*
3
1 2
2 4
2 4

2
1 2
2 4

3
2 2
4 4
4 4
*/

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i = 0; i < de.size(); i++){
      |                    ~~^~~~~~~~~~~
boat.cpp:55:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int j = 0; j < de.size(); j++){
      |                        ~~^~~~~~~~~~~
boat.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0; i < de.size() - 1; i++){
      |                    ~~^~~~~~~~~~~~~~~
boat.cpp:85:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for(int j = 0; j < bat[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~~
boat.cpp:89:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |             for(int k = 0; k < v.size() - 1; k++){
      |                            ~~^~~~~~~~~~~~~~
boat.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf(" %d",&N);
      |     ~~~~~^~~~~~~~~~
boat.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf(" %d",&a);
      |         ~~~~~^~~~~~~~~~
boat.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf(" %d",&b);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 199 ms 772 KB Output is correct
2 Correct 198 ms 344 KB Output is correct
3 Correct 198 ms 524 KB Output is correct
4 Correct 199 ms 348 KB Output is correct
5 Correct 198 ms 520 KB Output is correct
6 Correct 199 ms 348 KB Output is correct
7 Correct 198 ms 348 KB Output is correct
8 Correct 199 ms 540 KB Output is correct
9 Correct 198 ms 348 KB Output is correct
10 Correct 199 ms 520 KB Output is correct
11 Correct 199 ms 592 KB Output is correct
12 Correct 199 ms 348 KB Output is correct
13 Correct 198 ms 348 KB Output is correct
14 Correct 199 ms 520 KB Output is correct
15 Correct 199 ms 344 KB Output is correct
16 Correct 36 ms 348 KB Output is correct
17 Correct 38 ms 348 KB Output is correct
18 Correct 37 ms 344 KB Output is correct
19 Correct 39 ms 348 KB Output is correct
20 Correct 37 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 772 KB Output is correct
2 Correct 198 ms 344 KB Output is correct
3 Correct 198 ms 524 KB Output is correct
4 Correct 199 ms 348 KB Output is correct
5 Correct 198 ms 520 KB Output is correct
6 Correct 199 ms 348 KB Output is correct
7 Correct 198 ms 348 KB Output is correct
8 Correct 199 ms 540 KB Output is correct
9 Correct 198 ms 348 KB Output is correct
10 Correct 199 ms 520 KB Output is correct
11 Correct 199 ms 592 KB Output is correct
12 Correct 199 ms 348 KB Output is correct
13 Correct 198 ms 348 KB Output is correct
14 Correct 199 ms 520 KB Output is correct
15 Correct 199 ms 344 KB Output is correct
16 Correct 36 ms 348 KB Output is correct
17 Correct 38 ms 348 KB Output is correct
18 Correct 37 ms 344 KB Output is correct
19 Correct 39 ms 348 KB Output is correct
20 Correct 37 ms 348 KB Output is correct
21 Correct 407 ms 1368 KB Output is correct
22 Correct 398 ms 1732 KB Output is correct
23 Correct 382 ms 1368 KB Output is correct
24 Correct 398 ms 1452 KB Output is correct
25 Correct 394 ms 1372 KB Output is correct
26 Correct 509 ms 1708 KB Output is correct
27 Correct 525 ms 1876 KB Output is correct
28 Correct 511 ms 1628 KB Output is correct
29 Correct 510 ms 1716 KB Output is correct
30 Correct 199 ms 548 KB Output is correct
31 Correct 200 ms 552 KB Output is correct
32 Correct 198 ms 348 KB Output is correct
33 Correct 200 ms 348 KB Output is correct
34 Correct 199 ms 344 KB Output is correct
35 Correct 199 ms 348 KB Output is correct
36 Correct 199 ms 344 KB Output is correct
37 Correct 199 ms 568 KB Output is correct
38 Correct 198 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 348 KB Output is correct
2 Correct 42 ms 348 KB Output is correct
3 Correct 42 ms 344 KB Output is correct
4 Correct 42 ms 344 KB Output is correct
5 Correct 42 ms 348 KB Output is correct
6 Correct 44 ms 348 KB Output is correct
7 Correct 44 ms 348 KB Output is correct
8 Correct 44 ms 348 KB Output is correct
9 Correct 44 ms 472 KB Output is correct
10 Correct 44 ms 600 KB Output is correct
11 Correct 43 ms 520 KB Output is correct
12 Correct 42 ms 512 KB Output is correct
13 Correct 42 ms 348 KB Output is correct
14 Correct 42 ms 344 KB Output is correct
15 Correct 42 ms 344 KB Output is correct
16 Correct 25 ms 520 KB Output is correct
17 Correct 24 ms 348 KB Output is correct
18 Correct 24 ms 520 KB Output is correct
19 Correct 24 ms 344 KB Output is correct
20 Correct 23 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 772 KB Output is correct
2 Correct 198 ms 344 KB Output is correct
3 Correct 198 ms 524 KB Output is correct
4 Correct 199 ms 348 KB Output is correct
5 Correct 198 ms 520 KB Output is correct
6 Correct 199 ms 348 KB Output is correct
7 Correct 198 ms 348 KB Output is correct
8 Correct 199 ms 540 KB Output is correct
9 Correct 198 ms 348 KB Output is correct
10 Correct 199 ms 520 KB Output is correct
11 Correct 199 ms 592 KB Output is correct
12 Correct 199 ms 348 KB Output is correct
13 Correct 198 ms 348 KB Output is correct
14 Correct 199 ms 520 KB Output is correct
15 Correct 199 ms 344 KB Output is correct
16 Correct 36 ms 348 KB Output is correct
17 Correct 38 ms 348 KB Output is correct
18 Correct 37 ms 344 KB Output is correct
19 Correct 39 ms 348 KB Output is correct
20 Correct 37 ms 348 KB Output is correct
21 Correct 407 ms 1368 KB Output is correct
22 Correct 398 ms 1732 KB Output is correct
23 Correct 382 ms 1368 KB Output is correct
24 Correct 398 ms 1452 KB Output is correct
25 Correct 394 ms 1372 KB Output is correct
26 Correct 509 ms 1708 KB Output is correct
27 Correct 525 ms 1876 KB Output is correct
28 Correct 511 ms 1628 KB Output is correct
29 Correct 510 ms 1716 KB Output is correct
30 Correct 199 ms 548 KB Output is correct
31 Correct 200 ms 552 KB Output is correct
32 Correct 198 ms 348 KB Output is correct
33 Correct 200 ms 348 KB Output is correct
34 Correct 199 ms 344 KB Output is correct
35 Correct 199 ms 348 KB Output is correct
36 Correct 199 ms 344 KB Output is correct
37 Correct 199 ms 568 KB Output is correct
38 Correct 198 ms 348 KB Output is correct
39 Correct 42 ms 348 KB Output is correct
40 Correct 42 ms 348 KB Output is correct
41 Correct 42 ms 344 KB Output is correct
42 Correct 42 ms 344 KB Output is correct
43 Correct 42 ms 348 KB Output is correct
44 Correct 44 ms 348 KB Output is correct
45 Correct 44 ms 348 KB Output is correct
46 Correct 44 ms 348 KB Output is correct
47 Correct 44 ms 472 KB Output is correct
48 Correct 44 ms 600 KB Output is correct
49 Correct 43 ms 520 KB Output is correct
50 Correct 42 ms 512 KB Output is correct
51 Correct 42 ms 348 KB Output is correct
52 Correct 42 ms 344 KB Output is correct
53 Correct 42 ms 344 KB Output is correct
54 Correct 25 ms 520 KB Output is correct
55 Correct 24 ms 348 KB Output is correct
56 Correct 24 ms 520 KB Output is correct
57 Correct 24 ms 344 KB Output is correct
58 Correct 23 ms 344 KB Output is correct
59 Correct 506 ms 1536 KB Output is correct
60 Correct 491 ms 1624 KB Output is correct
61 Correct 473 ms 1620 KB Output is correct
62 Correct 506 ms 1628 KB Output is correct
63 Correct 499 ms 1372 KB Output is correct
64 Correct 720 ms 1884 KB Output is correct
65 Correct 725 ms 1892 KB Output is correct
66 Correct 721 ms 1884 KB Output is correct
67 Correct 722 ms 1880 KB Output is correct
68 Correct 718 ms 1880 KB Output is correct
69 Correct 473 ms 1400 KB Output is correct
70 Correct 465 ms 1616 KB Output is correct
71 Correct 463 ms 1396 KB Output is correct
72 Correct 474 ms 1408 KB Output is correct
73 Correct 481 ms 1396 KB Output is correct
74 Correct 84 ms 604 KB Output is correct
75 Correct 82 ms 604 KB Output is correct
76 Correct 86 ms 676 KB Output is correct
77 Correct 84 ms 604 KB Output is correct
78 Correct 85 ms 604 KB Output is correct