Submission #647305

# Submission time Handle Problem Language Result Execution time Memory
647305 2022-10-02T07:23:43 Z ghostwriter Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
356 ms 129356 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#else
#define debug(...)
#endif
#define ft front
#define bk back
#define st first
#define nd second
#define ins insert
#define ers erase
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define bg begin
#define ed end
#define all(x) (x).bg(), (x).ed()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define FSN(i, n) for (int (i) = (n) - 1; (i) >= 0; --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
----------------------------------------------------------------
    END OF TEMPLATE
----------------------------------------------------------------
    Tran The Bao - ghostwriter
    Training for VOI23 gold medal
----------------------------------------------------------------
    DIT ME CHUYEN BAO LOC
----------------------------------------------------------------
*/
const int oo = 1e9 + 5;
const int N = 202;
int n, l, x[N], t[N], rs = 0;
pi d[N][N][2][N];
#define dis(x, y) min((x - y + l) % l, (y - x + l) % l)
void minimize(pi &a, pi b) {
	a.nd = min(a.nd, oo);
	b.nd = min(b.nd, oo);
	if (!a.st && !b.st) {
		if (b.nd < a.nd) a = b;
		return;
	}
	if (a.st && !b.st) return;
	if (!a.st && b.st) {
		a = b;
		return;
	}
	if (a.nd > b.nd) a = b;
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);
    cin >> n >> l;
    FOR(i, 1, n) cin >> x[i];
    FOR(i, 1, n) cin >> t[i];
    FOR(i, 0, n + 1)
    FOR(j, 0, n + 1)
    FOR(stat, 0, 1)
    FOR(z, 0, n)
    	d[i][j][stat][z] = {0, oo};
    FOR(i, 0, n + 1)
    FOS(j, n + 1, i + 1)
    FOR(stat, 0, 1) 
    FOR(z, 0, n) {
    	pi &rs = d[i][j][stat][z];
    	if (i == 0 && j == n + 1) {
    		minimize(rs, !z? pi(1, 0) : pi(0, oo));
    		continue;
    	}
    	if (!stat) {
    		if (i) {
    			pi tmp = d[i - 1][j][0][z];
    			minimize(rs, {tmp.st, tmp.nd + dis(x[i], x[i - 1])});
    			tmp = d[i - 1][j][1][z];
    			minimize(rs, {tmp.st, tmp.nd + dis(x[i], x[j])});
    			if (z) {
	    			pi tmp = d[i - 1][j][0][z - 1];
	    			if (tmp.st && tmp.nd + dis(x[i], x[i - 1]) <= t[i]) {
	    				tmp.nd += dis(x[i], x[i - 1]);
	    				minimize(rs, tmp);
	    			}
	    			tmp = d[i - 1][j][1][z - 1];
	    			if (tmp.st && tmp.nd + dis(x[i], x[j]) <= t[i]) {
	    				tmp.nd += dis(x[i], x[j]);
	    				minimize(rs, tmp);
	    			}
    			}
    		}
    	}
    	else {
    		if (j <= n) {
    			pi tmp = d[i][j + 1][1][z];
    			minimize(rs, {tmp.st, tmp.nd + dis(x[j], x[j + 1])});
    			tmp = d[i][j + 1][0][z];
    			minimize(rs, {tmp.st, tmp.nd + dis(x[j], x[i])});
    			if (z) {
	    			pi tmp = d[i][j + 1][1][z - 1];
	    			if (tmp.st && tmp.nd + dis(x[j], x[j + 1]) <= t[j]) {
	    				tmp.nd += dis(x[j], x[j + 1]);
	    				minimize(rs, tmp);
	    			}
	    			tmp = d[i][j + 1][0][z - 1];
	    			if (tmp.st && tmp.nd + dis(x[j], x[i]) <= t[j]) {
	    				tmp.nd += dis(x[j], x[i]);
	    				minimize(rs, tmp);
	    			}
    			}
    		}
    	}
    }
    FOR(i, 0, n)
    FOS(j, n + 1, i + 1)
    FOR(stat, 0, 1)
    FOR(z, 0, n)
    	if (d[i][j][stat][z].st)
    		rs = max(rs, z);
    cout << rs;
    return 0;
}
/*
----------------------------------------------------------------
From Benq:
    stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * DON'T GET STUCK ON ONE APPROACH
----------------------------------------------------------------
*/

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:75:5: note: in expansion of macro 'FOR'
   75 |     FOR(i, 1, n) cin >> x[i];
      |     ^~~
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:76:5: note: in expansion of macro 'FOR'
   76 |     FOR(i, 1, n) cin >> t[i];
      |     ^~~
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:77:5: note: in expansion of macro 'FOR'
   77 |     FOR(i, 0, n + 1)
      |     ^~~
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:78:5: note: in expansion of macro 'FOR'
   78 |     FOR(j, 0, n + 1)
      |     ^~~
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'stat' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:79:5: note: in expansion of macro 'FOR'
   79 |     FOR(stat, 0, 1)
      |     ^~~
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:80:5: note: in expansion of macro 'FOR'
   80 |     FOR(z, 0, n)
      |     ^~~
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:82:5: note: in expansion of macro 'FOR'
   82 |     FOR(i, 0, n + 1)
      |     ^~~
ho_t3.cpp:33:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   33 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
ho_t3.cpp:83:5: note: in expansion of macro 'FOS'
   83 |     FOS(j, n + 1, i + 1)
      |     ^~~
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'stat' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:84:5: note: in expansion of macro 'FOR'
   84 |     FOR(stat, 0, 1)
      |     ^~~
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:85:5: note: in expansion of macro 'FOR'
   85 |     FOR(z, 0, n) {
      |     ^~~
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:132:5: note: in expansion of macro 'FOR'
  132 |     FOR(i, 0, n)
      |     ^~~
ho_t3.cpp:33:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   33 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
ho_t3.cpp:133:5: note: in expansion of macro 'FOS'
  133 |     FOS(j, n + 1, i + 1)
      |     ^~~
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'stat' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:134:5: note: in expansion of macro 'FOR'
  134 |     FOR(stat, 0, 1)
      |     ^~~
ho_t3.cpp:32:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t3.cpp:135:5: note: in expansion of macro 'FOR'
  135 |     FOR(z, 0, n)
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 1 ms 712 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 1 ms 712 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 1232 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 1 ms 1108 KB Output is correct
32 Correct 1 ms 972 KB Output is correct
33 Correct 1 ms 1236 KB Output is correct
34 Correct 1 ms 1236 KB Output is correct
35 Correct 1 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 1 ms 712 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 209 ms 104600 KB Output is correct
19 Correct 109 ms 63740 KB Output is correct
20 Correct 46 ms 34260 KB Output is correct
21 Correct 106 ms 60200 KB Output is correct
22 Correct 152 ms 77796 KB Output is correct
23 Correct 41 ms 29212 KB Output is correct
24 Correct 27 ms 22944 KB Output is correct
25 Correct 41 ms 28628 KB Output is correct
26 Correct 13 ms 11088 KB Output is correct
27 Correct 43 ms 29820 KB Output is correct
28 Correct 28 ms 21360 KB Output is correct
29 Correct 44 ms 30432 KB Output is correct
30 Correct 29 ms 24020 KB Output is correct
31 Correct 36 ms 28500 KB Output is correct
32 Correct 17 ms 15188 KB Output is correct
33 Correct 43 ms 28512 KB Output is correct
34 Correct 9 ms 10456 KB Output is correct
35 Correct 39 ms 27988 KB Output is correct
36 Correct 16 ms 13520 KB Output is correct
37 Correct 36 ms 29900 KB Output is correct
38 Correct 21 ms 16468 KB Output is correct
39 Correct 39 ms 31000 KB Output is correct
40 Correct 19 ms 18388 KB Output is correct
41 Correct 335 ms 128712 KB Output is correct
42 Correct 137 ms 87036 KB Output is correct
43 Correct 322 ms 128624 KB Output is correct
44 Correct 136 ms 86004 KB Output is correct
45 Correct 320 ms 128712 KB Output is correct
46 Correct 136 ms 86956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 1 ms 712 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 1232 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 1 ms 1108 KB Output is correct
32 Correct 1 ms 972 KB Output is correct
33 Correct 1 ms 1236 KB Output is correct
34 Correct 1 ms 1236 KB Output is correct
35 Correct 1 ms 1236 KB Output is correct
36 Correct 209 ms 104600 KB Output is correct
37 Correct 109 ms 63740 KB Output is correct
38 Correct 46 ms 34260 KB Output is correct
39 Correct 106 ms 60200 KB Output is correct
40 Correct 152 ms 77796 KB Output is correct
41 Correct 41 ms 29212 KB Output is correct
42 Correct 27 ms 22944 KB Output is correct
43 Correct 41 ms 28628 KB Output is correct
44 Correct 13 ms 11088 KB Output is correct
45 Correct 43 ms 29820 KB Output is correct
46 Correct 28 ms 21360 KB Output is correct
47 Correct 44 ms 30432 KB Output is correct
48 Correct 29 ms 24020 KB Output is correct
49 Correct 36 ms 28500 KB Output is correct
50 Correct 17 ms 15188 KB Output is correct
51 Correct 43 ms 28512 KB Output is correct
52 Correct 9 ms 10456 KB Output is correct
53 Correct 39 ms 27988 KB Output is correct
54 Correct 16 ms 13520 KB Output is correct
55 Correct 36 ms 29900 KB Output is correct
56 Correct 21 ms 16468 KB Output is correct
57 Correct 39 ms 31000 KB Output is correct
58 Correct 19 ms 18388 KB Output is correct
59 Correct 335 ms 128712 KB Output is correct
60 Correct 137 ms 87036 KB Output is correct
61 Correct 322 ms 128624 KB Output is correct
62 Correct 136 ms 86004 KB Output is correct
63 Correct 320 ms 128712 KB Output is correct
64 Correct 136 ms 86956 KB Output is correct
65 Correct 265 ms 116472 KB Output is correct
66 Correct 224 ms 106936 KB Output is correct
67 Correct 227 ms 102236 KB Output is correct
68 Correct 191 ms 94484 KB Output is correct
69 Correct 252 ms 115228 KB Output is correct
70 Correct 286 ms 110452 KB Output is correct
71 Correct 218 ms 111728 KB Output is correct
72 Correct 280 ms 112832 KB Output is correct
73 Correct 196 ms 104712 KB Output is correct
74 Correct 219 ms 97796 KB Output is correct
75 Correct 218 ms 108104 KB Output is correct
76 Correct 294 ms 123832 KB Output is correct
77 Correct 260 ms 123828 KB Output is correct
78 Correct 232 ms 95636 KB Output is correct
79 Correct 200 ms 99080 KB Output is correct
80 Correct 281 ms 121332 KB Output is correct
81 Correct 209 ms 100080 KB Output is correct
82 Correct 206 ms 105784 KB Output is correct
83 Correct 271 ms 128828 KB Output is correct
84 Correct 233 ms 110456 KB Output is correct
85 Correct 246 ms 120136 KB Output is correct
86 Correct 249 ms 117652 KB Output is correct
87 Correct 238 ms 108116 KB Output is correct
88 Correct 343 ms 129316 KB Output is correct
89 Correct 344 ms 129328 KB Output is correct
90 Correct 209 ms 109256 KB Output is correct
91 Correct 356 ms 129356 KB Output is correct
92 Correct 336 ms 129352 KB Output is correct
93 Correct 249 ms 127596 KB Output is correct