답안 #946716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946716 2024-03-15T00:08:32 Z Ice_man Boat (APIO16_boat) C++14
9 / 100
2000 ms 435860 KB
#include <iostream>
#include <chrono>
#include <set>
#include <vector>
#include <map>
#include <cstring>

#define maxn 505
#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++)
      |                    ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 472 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 472 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Runtime error 43 ms 1616 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2079 ms 435860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 472 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Runtime error 43 ms 1616 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -