Submission #1085996

# Submission time Handle Problem Language Result Execution time Memory
1085996 2024-09-09T09:20:02 Z Spy007 Boat (APIO16_boat) C++17
100 / 100
265 ms 10372 KB
#define Name Spy007
#include <bits/stdc++.h>
#define task "DL"
#define FOR(i,a,b) for (int i=(a),_b=(b);i<=_b;++i)
#define FOD(i,a,b) for (int i=(a),_b=(b);i>=_b;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define All(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define endl '\n'
#define PI 3.14159265

using namespace std;

typedef pair <int,int> ii;
typedef pair <int,ii> iii;
typedef pair <int,ll> ill;
typedef pair <ll,ll> lll;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

const int nmax = 500;
const ll mod = 1e9 + 7;

int n, m;
ll inv[nmax + 5], g[2 * nmax + 5][nmax + 5], c[nmax + 5][nmax + 5], dp[nmax + 5][2 * nmax + 5];
ii a[nmax + 5];
vi val;

ll Pow(ll a, ll b)
{
    if (b == 1) return a % mod;
    ll tmp = Pow(a, b / 2);
    tmp = (tmp * tmp) % mod;
    if (b & 1) return (tmp * a) % mod;
    else return tmp;
}

vi Treat(vi val)
{
    sort(All(val));
    vi ans;
    ans.pb(val[0]);
    FOR(i, 1, sz(val) - 1)
    if (val[i] != val[i - 1]) ans.pb(val[i]);
    return ans;
}

void Prep(void)
{
    val = Treat(val);
    FOR(i, 1, n) inv[i] = Pow(i, mod - 2);
    FOR(i, 1, n)
    {
        c[i][0] = 1;
        FOR(j, 1, i)
        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
    }
    m = sz(val);
    FOR(i, 1, m - 1)
    {
        int len = val[i] - val[i - 1];
        g[i][0] = 1;
        FOR(j, 1, n)
        g[i][j] = (g[i][j - 1] * (((j + len - 1) * inv[j]) % mod)) % mod;
    }
}

void Input(void)
{
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> a[i].fi >> a[i].se;
        val.pb(a[i].fi - 1);
        val.pb(a[i].se);
    }
}

void Solve(void)
{
    Prep();
    ll res = 0;
    FOR(i, 0, m - 1) dp[0][i] = 1;
    FOR(i, 1, n)
    {
        FOR(j, 1, m - 1)
        {
            if (a[i].fi <= val[j - 1] + 1 && val[j] <= a[i].se)
            {
                int cnt = 0;
                FOD(k, i, 1)
                {
                    if (a[k].fi <= val[j - 1] + 1 && val[j] <= a[k].se) cnt++;
                    dp[i][j] = (dp[i][j] + dp[k - 1][j - 1] * g[j][cnt]) % mod;
                }
                res = (res + dp[i][j]) % mod;
            }
            dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
        }
    }
    cout << res << endl;
}

signed main()
{
    fast;
    if (fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    Input();
    Solve();
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
boat.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10332 KB Output is correct
2 Correct 11 ms 10332 KB Output is correct
3 Correct 14 ms 10200 KB Output is correct
4 Correct 10 ms 10328 KB Output is correct
5 Correct 10 ms 10332 KB Output is correct
6 Correct 10 ms 10332 KB Output is correct
7 Correct 10 ms 10332 KB Output is correct
8 Correct 10 ms 10332 KB Output is correct
9 Correct 11 ms 10228 KB Output is correct
10 Correct 10 ms 10332 KB Output is correct
11 Correct 11 ms 10328 KB Output is correct
12 Correct 11 ms 10212 KB Output is correct
13 Correct 10 ms 10232 KB Output is correct
14 Correct 10 ms 10328 KB Output is correct
15 Correct 10 ms 10332 KB Output is correct
16 Correct 4 ms 5724 KB Output is correct
17 Correct 5 ms 5784 KB Output is correct
18 Correct 5 ms 5692 KB Output is correct
19 Correct 5 ms 5980 KB Output is correct
20 Correct 5 ms 5736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10332 KB Output is correct
2 Correct 11 ms 10332 KB Output is correct
3 Correct 14 ms 10200 KB Output is correct
4 Correct 10 ms 10328 KB Output is correct
5 Correct 10 ms 10332 KB Output is correct
6 Correct 10 ms 10332 KB Output is correct
7 Correct 10 ms 10332 KB Output is correct
8 Correct 10 ms 10332 KB Output is correct
9 Correct 11 ms 10228 KB Output is correct
10 Correct 10 ms 10332 KB Output is correct
11 Correct 11 ms 10328 KB Output is correct
12 Correct 11 ms 10212 KB Output is correct
13 Correct 10 ms 10232 KB Output is correct
14 Correct 10 ms 10328 KB Output is correct
15 Correct 10 ms 10332 KB Output is correct
16 Correct 4 ms 5724 KB Output is correct
17 Correct 5 ms 5784 KB Output is correct
18 Correct 5 ms 5692 KB Output is correct
19 Correct 5 ms 5980 KB Output is correct
20 Correct 5 ms 5736 KB Output is correct
21 Correct 167 ms 9804 KB Output is correct
22 Correct 164 ms 9808 KB Output is correct
23 Correct 157 ms 9808 KB Output is correct
24 Correct 162 ms 9808 KB Output is correct
25 Correct 161 ms 9780 KB Output is correct
26 Correct 229 ms 9812 KB Output is correct
27 Correct 233 ms 9816 KB Output is correct
28 Correct 230 ms 9816 KB Output is correct
29 Correct 228 ms 9804 KB Output is correct
30 Correct 11 ms 10328 KB Output is correct
31 Correct 12 ms 10324 KB Output is correct
32 Correct 12 ms 10120 KB Output is correct
33 Correct 12 ms 10328 KB Output is correct
34 Correct 12 ms 10332 KB Output is correct
35 Correct 12 ms 10332 KB Output is correct
36 Correct 11 ms 10372 KB Output is correct
37 Correct 12 ms 10332 KB Output is correct
38 Correct 11 ms 10332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2140 KB Output is correct
2 Correct 3 ms 2140 KB Output is correct
3 Correct 2 ms 2140 KB Output is correct
4 Correct 3 ms 2140 KB Output is correct
5 Correct 3 ms 2140 KB Output is correct
6 Correct 3 ms 2140 KB Output is correct
7 Correct 4 ms 2136 KB Output is correct
8 Correct 3 ms 2136 KB Output is correct
9 Correct 3 ms 2136 KB Output is correct
10 Correct 3 ms 2136 KB Output is correct
11 Correct 3 ms 2140 KB Output is correct
12 Correct 2 ms 2200 KB Output is correct
13 Correct 2 ms 2140 KB Output is correct
14 Correct 2 ms 2140 KB Output is correct
15 Correct 2 ms 2140 KB Output is correct
16 Correct 2 ms 1628 KB Output is correct
17 Correct 2 ms 1624 KB Output is correct
18 Correct 2 ms 1624 KB Output is correct
19 Correct 2 ms 1880 KB Output is correct
20 Correct 2 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10332 KB Output is correct
2 Correct 11 ms 10332 KB Output is correct
3 Correct 14 ms 10200 KB Output is correct
4 Correct 10 ms 10328 KB Output is correct
5 Correct 10 ms 10332 KB Output is correct
6 Correct 10 ms 10332 KB Output is correct
7 Correct 10 ms 10332 KB Output is correct
8 Correct 10 ms 10332 KB Output is correct
9 Correct 11 ms 10228 KB Output is correct
10 Correct 10 ms 10332 KB Output is correct
11 Correct 11 ms 10328 KB Output is correct
12 Correct 11 ms 10212 KB Output is correct
13 Correct 10 ms 10232 KB Output is correct
14 Correct 10 ms 10328 KB Output is correct
15 Correct 10 ms 10332 KB Output is correct
16 Correct 4 ms 5724 KB Output is correct
17 Correct 5 ms 5784 KB Output is correct
18 Correct 5 ms 5692 KB Output is correct
19 Correct 5 ms 5980 KB Output is correct
20 Correct 5 ms 5736 KB Output is correct
21 Correct 167 ms 9804 KB Output is correct
22 Correct 164 ms 9808 KB Output is correct
23 Correct 157 ms 9808 KB Output is correct
24 Correct 162 ms 9808 KB Output is correct
25 Correct 161 ms 9780 KB Output is correct
26 Correct 229 ms 9812 KB Output is correct
27 Correct 233 ms 9816 KB Output is correct
28 Correct 230 ms 9816 KB Output is correct
29 Correct 228 ms 9804 KB Output is correct
30 Correct 11 ms 10328 KB Output is correct
31 Correct 12 ms 10324 KB Output is correct
32 Correct 12 ms 10120 KB Output is correct
33 Correct 12 ms 10328 KB Output is correct
34 Correct 12 ms 10332 KB Output is correct
35 Correct 12 ms 10332 KB Output is correct
36 Correct 11 ms 10372 KB Output is correct
37 Correct 12 ms 10332 KB Output is correct
38 Correct 11 ms 10332 KB Output is correct
39 Correct 2 ms 2140 KB Output is correct
40 Correct 3 ms 2140 KB Output is correct
41 Correct 2 ms 2140 KB Output is correct
42 Correct 3 ms 2140 KB Output is correct
43 Correct 3 ms 2140 KB Output is correct
44 Correct 3 ms 2140 KB Output is correct
45 Correct 4 ms 2136 KB Output is correct
46 Correct 3 ms 2136 KB Output is correct
47 Correct 3 ms 2136 KB Output is correct
48 Correct 3 ms 2136 KB Output is correct
49 Correct 3 ms 2140 KB Output is correct
50 Correct 2 ms 2200 KB Output is correct
51 Correct 2 ms 2140 KB Output is correct
52 Correct 2 ms 2140 KB Output is correct
53 Correct 2 ms 2140 KB Output is correct
54 Correct 2 ms 1628 KB Output is correct
55 Correct 2 ms 1624 KB Output is correct
56 Correct 2 ms 1624 KB Output is correct
57 Correct 2 ms 1880 KB Output is correct
58 Correct 2 ms 1628 KB Output is correct
59 Correct 182 ms 10276 KB Output is correct
60 Correct 176 ms 10152 KB Output is correct
61 Correct 166 ms 10324 KB Output is correct
62 Correct 186 ms 10324 KB Output is correct
63 Correct 181 ms 10320 KB Output is correct
64 Correct 265 ms 10324 KB Output is correct
65 Correct 263 ms 10308 KB Output is correct
66 Correct 260 ms 10324 KB Output is correct
67 Correct 262 ms 10196 KB Output is correct
68 Correct 261 ms 10328 KB Output is correct
69 Correct 146 ms 10320 KB Output is correct
70 Correct 139 ms 10228 KB Output is correct
71 Correct 137 ms 10324 KB Output is correct
72 Correct 149 ms 10320 KB Output is correct
73 Correct 146 ms 10324 KB Output is correct
74 Correct 37 ms 5848 KB Output is correct
75 Correct 37 ms 5712 KB Output is correct
76 Correct 37 ms 5716 KB Output is correct
77 Correct 38 ms 5816 KB Output is correct
78 Correct 38 ms 5820 KB Output is correct