Submission #668382

# Submission time Handle Problem Language Result Execution time Memory
668382 2022-12-03T18:05:17 Z danikoynov Boat (APIO16_boat) C++14
31 / 100
2000 ms 324404 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 510, maxa = 1e6 + 10;
const ll mod = 1e9 + 7;

int n, a[maxn], b[maxn];
ll dp[maxn], fp[maxa];

void solve()
{
    cin >> n;
    bool diff = false;
    for (int i = 1; i <= n; i ++)
    {
        cin >> a[i] >> b[i];
        if (a[i] != b[i])
            diff = true;
    }

    if (!diff)
    {
        ll ans = 0;
    for (int i = 1; i <= n; i ++)
    {
        dp[i] = 1;
        for (int j = 1; j < i; j ++)
        {
            if (a[i] > a[j])
                dp[i] = (dp[i] + dp[j]) % mod;
        }

        ans = (ans + dp[i]) % mod;
    }
    cout << ans << endl;
    }
    else
    {
        set < int > st;
        for (int i = 1; i <= n; i ++)
            for (int j = a[i]; j <= b[i]; j ++)
            st.insert(j);

        map < int, int > mp;
        int idx = 0;
        for (int cur : st)
            mp[cur] = ++ idx;

        fp[0] = 1;
        for (int i = 1; i <= n; i ++)
        {
            a[i] = mp[a[i]];
            b[i] = mp[b[i]];

            ll sum = 0;
            for (int j = 0; j < a[i]; j ++)
            {
                sum = sum + fp[j];
                if (sum >= mod)
                    sum -= mod;
            }

            ll lsum = sum;
            for (int j = a[i]; j <= b[i]; j ++)
            {

                sum = sum + fp[j];
                if (sum >= mod)
                    sum -= mod;

                fp[j] = (fp[j] + lsum);
                if (fp[j] >= mod)
                    fp[j] -= mod;

                lsum = sum;

            }

            /**for (int j = 0; j < 10; j ++)
                cout << fp[j] << " ";
            cout << endl;*/
        }

        ll ans = 0;
        for (int i = 1; i < maxa; i ++)
        {
            ans = ans + fp[i];
            if (ans >= mod)
                ans -= mod;
        }
        cout << ans << endl;
    }


}

int main()
{
    solve();
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 34 ms 804 KB Output is correct
22 Correct 41 ms 804 KB Output is correct
23 Correct 28 ms 800 KB Output is correct
24 Correct 32 ms 820 KB Output is correct
25 Correct 37 ms 796 KB Output is correct
26 Correct 31 ms 596 KB Output is correct
27 Correct 31 ms 588 KB Output is correct
28 Correct 33 ms 604 KB Output is correct
29 Correct 30 ms 612 KB Output is correct
30 Correct 698 ms 100996 KB Output is correct
31 Correct 654 ms 99140 KB Output is correct
32 Correct 660 ms 100972 KB Output is correct
33 Correct 647 ms 98320 KB Output is correct
34 Correct 642 ms 99300 KB Output is correct
35 Correct 586 ms 94692 KB Output is correct
36 Correct 584 ms 97960 KB Output is correct
37 Correct 594 ms 99088 KB Output is correct
38 Correct 585 ms 95760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 324404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 34 ms 804 KB Output is correct
22 Correct 41 ms 804 KB Output is correct
23 Correct 28 ms 800 KB Output is correct
24 Correct 32 ms 820 KB Output is correct
25 Correct 37 ms 796 KB Output is correct
26 Correct 31 ms 596 KB Output is correct
27 Correct 31 ms 588 KB Output is correct
28 Correct 33 ms 604 KB Output is correct
29 Correct 30 ms 612 KB Output is correct
30 Correct 698 ms 100996 KB Output is correct
31 Correct 654 ms 99140 KB Output is correct
32 Correct 660 ms 100972 KB Output is correct
33 Correct 647 ms 98320 KB Output is correct
34 Correct 642 ms 99300 KB Output is correct
35 Correct 586 ms 94692 KB Output is correct
36 Correct 584 ms 97960 KB Output is correct
37 Correct 594 ms 99088 KB Output is correct
38 Correct 585 ms 95760 KB Output is correct
39 Execution timed out 2075 ms 324404 KB Time limit exceeded
40 Halted 0 ms 0 KB -