Submission #946522

# Submission time Handle Problem Language Result Execution time Memory
946522 2024-03-14T17:57:47 Z n3rm1n Boat (APIO16_boat) C++17
0 / 100
2000 ms 524288 KB
/// boat
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const long long MAXN = 505, MAXX = 1e6+10;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
long long n, m;
long long a[MAXN], b[MAXN];
unordered_map < long long, long long > id;
vector < long long > g, u;
void read_hash()
{
    cin >> n;
    for (long long i = 1; i <= n; ++ i)
    {
        cin >> a[i] >> b[i];
        for (long long j = a[i]; j <= b[i]; ++ j)
            g.push_back(j);
    }
    sort(g.begin(), g.end());
    u.push_back(g[0]);
    for (long long i = 1; i < g.size(); ++ i)
    {
        if(u.back() != g[i])
        {
            u.push_back(g[i]);

        }
    }
    for (long long i = 0; i < u.size(); ++ i)
    {
        id[u[i]] = i+1;
    }
}

long long dp[MAXX];
const long long mod = 1e9 + 7;
long long pref[MAXX];
void solve()
{
    long long ans = 0;
    long long maxx = 1e6;
    for (long long i = 1; i <= n; ++ i)
    {
        for (long long j = 1; j <= 1e6; ++ j)
            pref[j] = (pref[j-1] + dp[j]) % mod;
        for (long long j = id[b[i]]; j >= id[a[i]]; -- j)
        {
            dp[j] += pref[j-1] + 1;
            dp[j] %= mod;
        }

    }
    for (long long j = 1; j <= maxx; ++ j)
            pref[j] = pref[j-1] + dp[j];
    ans += pref[maxx];
    ans %= mod;
    cout << ans << endl;
}
int main()
{
    speed();

    read_hash();
    solve();
    return 0;
}

Compilation message

boat.cpp: In function 'void read_hash()':
boat.cpp:27:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (long long i = 1; i < g.size(); ++ i)
      |                           ~~^~~~~~~~~~
boat.cpp:35:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (long long i = 0; i < u.size(); ++ i)
      |                           ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2048 ms 8284 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2048 ms 8284 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 258 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2048 ms 8284 KB Time limit exceeded
2 Halted 0 ms 0 KB -