Submission #946717

# Submission time Handle Problem Language Result Execution time Memory
946717 2024-03-15T00:09:15 Z Ice_man Boat (APIO16_boat) C++14
31 / 100
2000 ms 421516 KB
#include <iostream>
#include <chrono>
#include <set>
#include <vector>
#include <map>
#include <cstring>

#define maxn 1000005
#define maxlog 20
#define mod 1000000007
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;

#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")
#pragma GCC target("avx2")

using namespace std;

std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;

double timePassed()
{
    using namespace std::chrono;
    currT = high_resolution_clock::now();
    double time = duration_cast<duration<double>>(currT - startT).count();
    return time * TIME_MULT;
}

int l[maxn], r[maxn];
int n;
int dp[maxn];

void read()
{
    cin >> n;

    for(int i = 0; i < n; i++)
        cin >> l[i] >> r[i];
}

int ans = 0;

void calc_dp()
{
    set <int> s;

    for(int i = 0; i < n; i++)
        for(int j = l[i]; j <= r[i]; j++)
            s.insert(j);

    vector <int> v;

    for(int e : s)
        v.pb(e);

    /**for(int e : v)
        cout << e << " ";
    cout << endl;*/

    map <int , int> mem;

    for(int i = 0; i < v.size(); i++)
        mem[v[i]] = i + 1;

    for(int i = 0; i < n; i++)
    {
        l[i] = mem[l[i]];
        r[i] = mem[r[i]];
    }

    /**for(int i = 0; i < n; i++)
        cout << l[i] << " - " << r[i] << endl;*/



    for(int i = 0; i <= v.size(); i++)
        dp[i] = 0;

    dp[0] = 1;

    long long pom = 0 , prev;

    for(int i = 0; i < n; i++)
    {
        pom = 0LL;

        for(int j = 0; j <= r[i]; j++)
        {
            prev = dp[j];

            if(j >= l[i])
            {
                dp[j] += pom;
                dp[j] %= mod;
            }

            pom += prev;
            pom %= mod;
        }

    }

    long long ans = 0;

    for(int i = 1; i <= v.size(); i++)
    {
        ans += dp[i];
        ans %= mod;
    }

    cout << ans << endl;

}





int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    //startT = std::chrono::high_resolution_clock::now();

    read();
    calc_dp();


    return 0;
}

Compilation message

boat.cpp: In function 'void calc_dp()':
boat.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i = 0; i < v.size(); i++)
      |                    ~~^~~~~~~~~~
boat.cpp:82:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i = 0; i <= v.size(); i++)
      |                    ~~^~~~~~~~~~~
boat.cpp:111:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for(int i = 1; i <= v.size(); i++)
      |                    ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 3 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 3 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 51 ms 5076 KB Output is correct
22 Correct 49 ms 4944 KB Output is correct
23 Correct 47 ms 5320 KB Output is correct
24 Correct 51 ms 5104 KB Output is correct
25 Correct 51 ms 4944 KB Output is correct
26 Correct 52 ms 4976 KB Output is correct
27 Correct 54 ms 4740 KB Output is correct
28 Correct 53 ms 4952 KB Output is correct
29 Correct 52 ms 4944 KB Output is correct
30 Correct 964 ms 103288 KB Output is correct
31 Correct 936 ms 101816 KB Output is correct
32 Correct 957 ms 103460 KB Output is correct
33 Correct 949 ms 100876 KB Output is correct
34 Correct 952 ms 101708 KB Output is correct
35 Correct 912 ms 97724 KB Output is correct
36 Correct 927 ms 100656 KB Output is correct
37 Correct 944 ms 101532 KB Output is correct
38 Correct 910 ms 98492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2029 ms 421516 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 3 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 51 ms 5076 KB Output is correct
22 Correct 49 ms 4944 KB Output is correct
23 Correct 47 ms 5320 KB Output is correct
24 Correct 51 ms 5104 KB Output is correct
25 Correct 51 ms 4944 KB Output is correct
26 Correct 52 ms 4976 KB Output is correct
27 Correct 54 ms 4740 KB Output is correct
28 Correct 53 ms 4952 KB Output is correct
29 Correct 52 ms 4944 KB Output is correct
30 Correct 964 ms 103288 KB Output is correct
31 Correct 936 ms 101816 KB Output is correct
32 Correct 957 ms 103460 KB Output is correct
33 Correct 949 ms 100876 KB Output is correct
34 Correct 952 ms 101708 KB Output is correct
35 Correct 912 ms 97724 KB Output is correct
36 Correct 927 ms 100656 KB Output is correct
37 Correct 944 ms 101532 KB Output is correct
38 Correct 910 ms 98492 KB Output is correct
39 Execution timed out 2029 ms 421516 KB Time limit exceeded
40 Halted 0 ms 0 KB -