Submission #943818

# Submission time Handle Problem Language Result Execution time Memory
943818 2024-03-12T01:34:58 Z Boycl07 Boat (APIO16_boat) C++17
100 / 100
574 ms 5000 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "boat"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }

inline int readInt()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ll readLong()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll  n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}


const int N =  1e3 + 10;
const int M = 1e3 + 3;
const int N1 = 2e3 + 10;
const int K = 1e2 + 1;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LINF = 1e17 + 2;
const int block_size = 500;
const int LOG = 40;
const int offset = N;
const int LIM = 11 ;
const int AL = 26;

int add(int x, int y)
{
    x += y;
    if(x >= MOD) x -= MOD;
    if(x < 0) x += MOD;
    return x;
}

int mul(int x, int y)
{
    return 1ll * x * y % MOD;
}

int n;

int a[N], b[N];

int C[N][N];

int comb[N], inv[N];

int dp[N][N];

vector<int> zip;

void solve()
{
    cin >> n;
    rep(i, n)
    {
        cin >> a[i] >> b[i];
        zip.pb(a[i]);
        zip.pb(b[i] + 1);
    }
    sort(all(zip));
    zip.resize(unique(all(zip)) - zip.begin());

//    rep(i, n) a[i] = upper_bound(all(zip), a[i]) - zip.begin();
//    rep(i, n) b[i] = upper_bound(all(zip), b[i]) - zip.begin();

    int m = sz(zip);
    dp[0][0] = 1;
    inv[0] = inv[1] = 1;
    forn(i, 2, 2 * n) inv[i] = add(MOD, -mul(inv[MOD % i], MOD / i));
    forn(i, 0, m - 1)
    {
        int l, r;
        l = zip[i], r = i == m - 1 ? zip[i]  : zip[i + 1];
        comb[0] = 1;
        forn(k, 1, n) comb[k] = mul(comb[k - 1], mul(inv[k], (r - l + k - 1)));
        forn(j, 0, n)
        {
            dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
            int cnt = 0, cur = 1;


            forn(k, j + 1, n)
            {
                if(a[k] <= l && b[k] >= r - 1)
                {
                    dp[i + 1][k] = add(dp[i + 1][k], mul(dp[i][j], comb[++cnt]));
                }
            }
        }
    }
    int res = 0;
    forn(i, 1, n) res = add(res, dp[m][i]);
    cout << res << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int TC = 1;

    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }


    while(TC--)
    {
        solve();
        cout << endl;
    }

    return 0;
}

Compilation message

boat.cpp: In function 'void solve()':
boat.cpp:98:26: warning: unused variable 'cur' [-Wunused-variable]
   98 |             int cnt = 0, cur = 1;
      |                          ^~~
boat.cpp: In function 'int main()':
boat.cpp:124:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  124 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:125:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 131 ms 4740 KB Output is correct
2 Correct 130 ms 4580 KB Output is correct
3 Correct 131 ms 4688 KB Output is correct
4 Correct 133 ms 4552 KB Output is correct
5 Correct 132 ms 4740 KB Output is correct
6 Correct 83 ms 4732 KB Output is correct
7 Correct 83 ms 4560 KB Output is correct
8 Correct 86 ms 4720 KB Output is correct
9 Correct 87 ms 4732 KB Output is correct
10 Correct 83 ms 4696 KB Output is correct
11 Correct 84 ms 4740 KB Output is correct
12 Correct 90 ms 4520 KB Output is correct
13 Correct 84 ms 4620 KB Output is correct
14 Correct 82 ms 4736 KB Output is correct
15 Correct 84 ms 4700 KB Output is correct
16 Correct 26 ms 3160 KB Output is correct
17 Correct 28 ms 3156 KB Output is correct
18 Correct 27 ms 3160 KB Output is correct
19 Correct 28 ms 3164 KB Output is correct
20 Correct 27 ms 3076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 4740 KB Output is correct
2 Correct 130 ms 4580 KB Output is correct
3 Correct 131 ms 4688 KB Output is correct
4 Correct 133 ms 4552 KB Output is correct
5 Correct 132 ms 4740 KB Output is correct
6 Correct 83 ms 4732 KB Output is correct
7 Correct 83 ms 4560 KB Output is correct
8 Correct 86 ms 4720 KB Output is correct
9 Correct 87 ms 4732 KB Output is correct
10 Correct 83 ms 4696 KB Output is correct
11 Correct 84 ms 4740 KB Output is correct
12 Correct 90 ms 4520 KB Output is correct
13 Correct 84 ms 4620 KB Output is correct
14 Correct 82 ms 4736 KB Output is correct
15 Correct 84 ms 4700 KB Output is correct
16 Correct 26 ms 3160 KB Output is correct
17 Correct 28 ms 3156 KB Output is correct
18 Correct 27 ms 3160 KB Output is correct
19 Correct 28 ms 3164 KB Output is correct
20 Correct 27 ms 3076 KB Output is correct
21 Correct 404 ms 4692 KB Output is correct
22 Correct 383 ms 4692 KB Output is correct
23 Correct 373 ms 4692 KB Output is correct
24 Correct 399 ms 4640 KB Output is correct
25 Correct 384 ms 4732 KB Output is correct
26 Correct 400 ms 4692 KB Output is correct
27 Correct 419 ms 4776 KB Output is correct
28 Correct 419 ms 4660 KB Output is correct
29 Correct 424 ms 4488 KB Output is correct
30 Correct 88 ms 4740 KB Output is correct
31 Correct 98 ms 4696 KB Output is correct
32 Correct 88 ms 4536 KB Output is correct
33 Correct 85 ms 4732 KB Output is correct
34 Correct 109 ms 4540 KB Output is correct
35 Correct 134 ms 4732 KB Output is correct
36 Correct 137 ms 4688 KB Output is correct
37 Correct 134 ms 4692 KB Output is correct
38 Correct 134 ms 4740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3164 KB Output is correct
2 Correct 5 ms 3160 KB Output is correct
3 Correct 6 ms 3164 KB Output is correct
4 Correct 6 ms 3164 KB Output is correct
5 Correct 6 ms 3192 KB Output is correct
6 Correct 6 ms 3164 KB Output is correct
7 Correct 6 ms 3164 KB Output is correct
8 Correct 6 ms 3164 KB Output is correct
9 Correct 6 ms 3164 KB Output is correct
10 Correct 7 ms 3164 KB Output is correct
11 Correct 5 ms 3164 KB Output is correct
12 Correct 5 ms 3164 KB Output is correct
13 Correct 5 ms 3164 KB Output is correct
14 Correct 5 ms 3164 KB Output is correct
15 Correct 5 ms 3164 KB Output is correct
16 Correct 3 ms 2908 KB Output is correct
17 Correct 3 ms 2908 KB Output is correct
18 Correct 3 ms 2908 KB Output is correct
19 Correct 3 ms 2876 KB Output is correct
20 Correct 3 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 4740 KB Output is correct
2 Correct 130 ms 4580 KB Output is correct
3 Correct 131 ms 4688 KB Output is correct
4 Correct 133 ms 4552 KB Output is correct
5 Correct 132 ms 4740 KB Output is correct
6 Correct 83 ms 4732 KB Output is correct
7 Correct 83 ms 4560 KB Output is correct
8 Correct 86 ms 4720 KB Output is correct
9 Correct 87 ms 4732 KB Output is correct
10 Correct 83 ms 4696 KB Output is correct
11 Correct 84 ms 4740 KB Output is correct
12 Correct 90 ms 4520 KB Output is correct
13 Correct 84 ms 4620 KB Output is correct
14 Correct 82 ms 4736 KB Output is correct
15 Correct 84 ms 4700 KB Output is correct
16 Correct 26 ms 3160 KB Output is correct
17 Correct 28 ms 3156 KB Output is correct
18 Correct 27 ms 3160 KB Output is correct
19 Correct 28 ms 3164 KB Output is correct
20 Correct 27 ms 3076 KB Output is correct
21 Correct 404 ms 4692 KB Output is correct
22 Correct 383 ms 4692 KB Output is correct
23 Correct 373 ms 4692 KB Output is correct
24 Correct 399 ms 4640 KB Output is correct
25 Correct 384 ms 4732 KB Output is correct
26 Correct 400 ms 4692 KB Output is correct
27 Correct 419 ms 4776 KB Output is correct
28 Correct 419 ms 4660 KB Output is correct
29 Correct 424 ms 4488 KB Output is correct
30 Correct 88 ms 4740 KB Output is correct
31 Correct 98 ms 4696 KB Output is correct
32 Correct 88 ms 4536 KB Output is correct
33 Correct 85 ms 4732 KB Output is correct
34 Correct 109 ms 4540 KB Output is correct
35 Correct 134 ms 4732 KB Output is correct
36 Correct 137 ms 4688 KB Output is correct
37 Correct 134 ms 4692 KB Output is correct
38 Correct 134 ms 4740 KB Output is correct
39 Correct 6 ms 3164 KB Output is correct
40 Correct 5 ms 3160 KB Output is correct
41 Correct 6 ms 3164 KB Output is correct
42 Correct 6 ms 3164 KB Output is correct
43 Correct 6 ms 3192 KB Output is correct
44 Correct 6 ms 3164 KB Output is correct
45 Correct 6 ms 3164 KB Output is correct
46 Correct 6 ms 3164 KB Output is correct
47 Correct 6 ms 3164 KB Output is correct
48 Correct 7 ms 3164 KB Output is correct
49 Correct 5 ms 3164 KB Output is correct
50 Correct 5 ms 3164 KB Output is correct
51 Correct 5 ms 3164 KB Output is correct
52 Correct 5 ms 3164 KB Output is correct
53 Correct 5 ms 3164 KB Output is correct
54 Correct 3 ms 2908 KB Output is correct
55 Correct 3 ms 2908 KB Output is correct
56 Correct 3 ms 2908 KB Output is correct
57 Correct 3 ms 2876 KB Output is correct
58 Correct 3 ms 2908 KB Output is correct
59 Correct 495 ms 4628 KB Output is correct
60 Correct 484 ms 4880 KB Output is correct
61 Correct 453 ms 4824 KB Output is correct
62 Correct 499 ms 4524 KB Output is correct
63 Correct 496 ms 4716 KB Output is correct
64 Correct 560 ms 4944 KB Output is correct
65 Correct 562 ms 4656 KB Output is correct
66 Correct 574 ms 4948 KB Output is correct
67 Correct 557 ms 4868 KB Output is correct
68 Correct 569 ms 4528 KB Output is correct
69 Correct 433 ms 4692 KB Output is correct
70 Correct 418 ms 5000 KB Output is correct
71 Correct 416 ms 4688 KB Output is correct
72 Correct 432 ms 4772 KB Output is correct
73 Correct 433 ms 4692 KB Output is correct
74 Correct 72 ms 3152 KB Output is correct
75 Correct 72 ms 3104 KB Output is correct
76 Correct 72 ms 3096 KB Output is correct
77 Correct 70 ms 3156 KB Output is correct
78 Correct 70 ms 3008 KB Output is correct