Submission #1084219

# Submission time Handle Problem Language Result Execution time Memory
1084219 2024-09-05T16:19:15 Z anhthi Trains (BOI24_trains) C++14
100 / 100
273 ms 357688 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define clz __builtin_clzll
#define ctz __builtin_ctzll
#define popcount __builtin_popcount
#define lg(x) (63 - clz(x))
 
template <class X, class Y>
    inline bool maximize(X &x, Y y) {
        return (x < y ? x = y, true : false);
    }
template <class X, class Y>
    inline bool minimize(X &x, Y y) {
        return (x > y ? x = y, true : false);
    }
template <class X>
    inline void compress(vector<X> &a) {
        sort(all(a)); a.resize(unique(all(a)) - a.begin());
    }
 
const ll oo = (ll) 1e18, inf = (ll) 1e9, mod = (ll) 1e9 + 7;
const int mxn = (int) 2e5 + 5, S = (int) 450, S2 = (int) 450, lg = (int) 17;
 
void add(ll &x, ll y) {
    x += y;
    if (x >= mod) x -= mod;
}
 
void sub(ll &x, ll y) {
    x -= y;
    if (x < 0) x += mod;
}
 
 
ll n;
pair<ll, ll> a[mxn];
 
ll f[mxn + S];
ll calc[mxn + S][S+1];
 
void solve() {
 
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i].se >> a[i].fi;
    }
 
    for (int i = n; i >= 1; --i) {
        f[i] = 1;
        if (a[i].fi <= S) {
            if (a[i].se) {
                for (int j = 1; j <= a[i].fi; ++j) {
                    if (i + j * a[i].se > n) break;
                    add(f[i], f[i + j * a[i].se]);
                }
            }
        }
        else {
            if (a[i].se > S) {
                for (int j = 1; j <= a[i].fi; ++j) {
                    if (i + j * a[i].se > n) break;
                    add(f[i], f[i + j * a[i].se]);
                }
            }
            else {
                if (a[i].se) {
                    add(f[i], calc[i + a[i].se][a[i].se]);
                    sub(f[i], calc[min(n + 1, i + a[i].se * (a[i].fi + 1))][a[i].se]);
                }
            }
        }
        for (int d = 1; d <= S; ++d) {
            add(calc[i][d], f[i]);
            add(calc[i][d], calc[i + d][d]);
        }
        // cout << i << ' ' << f[i] << '\n';
 
    }
 
    cout << f[1];
 
    return;
}
 
int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 
    #define TASK "task"
    if (fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }
 
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
 
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 29780 KB Output is correct
21 Correct 7 ms 10844 KB Output is correct
22 Correct 23 ms 35932 KB Output is correct
23 Correct 17 ms 23460 KB Output is correct
24 Correct 11 ms 14936 KB Output is correct
25 Correct 22 ms 32128 KB Output is correct
26 Correct 12 ms 16472 KB Output is correct
27 Correct 19 ms 30808 KB Output is correct
28 Correct 22 ms 35928 KB Output is correct
29 Correct 23 ms 35920 KB Output is correct
30 Correct 27 ms 35924 KB Output is correct
31 Correct 23 ms 35928 KB Output is correct
32 Correct 24 ms 35928 KB Output is correct
33 Correct 23 ms 35960 KB Output is correct
34 Correct 22 ms 35932 KB Output is correct
35 Correct 25 ms 36048 KB Output is correct
36 Correct 25 ms 36064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 14 ms 23396 KB Output is correct
3 Correct 11 ms 16476 KB Output is correct
4 Correct 23 ms 30872 KB Output is correct
5 Correct 184 ms 275280 KB Output is correct
6 Correct 214 ms 356728 KB Output is correct
7 Correct 220 ms 356692 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 28 ms 36008 KB Output is correct
12 Correct 222 ms 356896 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 24 ms 36068 KB Output is correct
15 Correct 226 ms 356796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 172116 KB Output is correct
2 Correct 91 ms 142928 KB Output is correct
3 Correct 212 ms 356944 KB Output is correct
4 Correct 153 ms 255824 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 23 ms 36080 KB Output is correct
8 Correct 207 ms 356952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 29780 KB Output is correct
21 Correct 7 ms 10844 KB Output is correct
22 Correct 23 ms 35932 KB Output is correct
23 Correct 17 ms 23460 KB Output is correct
24 Correct 11 ms 14936 KB Output is correct
25 Correct 22 ms 32128 KB Output is correct
26 Correct 12 ms 16472 KB Output is correct
27 Correct 19 ms 30808 KB Output is correct
28 Correct 22 ms 35928 KB Output is correct
29 Correct 23 ms 35920 KB Output is correct
30 Correct 27 ms 35924 KB Output is correct
31 Correct 23 ms 35928 KB Output is correct
32 Correct 24 ms 35928 KB Output is correct
33 Correct 23 ms 35960 KB Output is correct
34 Correct 22 ms 35932 KB Output is correct
35 Correct 25 ms 36048 KB Output is correct
36 Correct 25 ms 36064 KB Output is correct
37 Correct 1 ms 352 KB Output is correct
38 Correct 14 ms 23396 KB Output is correct
39 Correct 11 ms 16476 KB Output is correct
40 Correct 23 ms 30872 KB Output is correct
41 Correct 184 ms 275280 KB Output is correct
42 Correct 214 ms 356728 KB Output is correct
43 Correct 220 ms 356692 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 28 ms 36008 KB Output is correct
48 Correct 222 ms 356896 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 24 ms 36068 KB Output is correct
51 Correct 226 ms 356796 KB Output is correct
52 Correct 108 ms 172116 KB Output is correct
53 Correct 91 ms 142928 KB Output is correct
54 Correct 212 ms 356944 KB Output is correct
55 Correct 153 ms 255824 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 23 ms 36080 KB Output is correct
59 Correct 207 ms 356952 KB Output is correct
60 Correct 190 ms 297408 KB Output is correct
61 Correct 202 ms 356688 KB Output is correct
62 Correct 245 ms 356404 KB Output is correct
63 Correct 222 ms 356688 KB Output is correct
64 Correct 224 ms 357688 KB Output is correct
65 Correct 240 ms 357196 KB Output is correct
66 Correct 218 ms 356896 KB Output is correct
67 Correct 201 ms 357204 KB Output is correct
68 Correct 236 ms 356952 KB Output is correct
69 Correct 273 ms 356544 KB Output is correct
70 Correct 219 ms 356972 KB Output is correct
71 Correct 212 ms 356696 KB Output is correct
72 Correct 219 ms 356692 KB Output is correct