Submission #680904

# Submission time Handle Problem Language Result Execution time Memory
680904 2023-01-12T02:12:14 Z SanguineChameleon Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
105 ms 83764 KB
// BEGIN BOILERPLATE CODE

#include <bits/stdc++.h>
using namespace std;

#ifdef KAMIRULEZ
	const bool kami_loc = true;
	const long long kami_seed = 69420;
#else
	const bool kami_loc = false;
	const long long kami_seed = chrono::steady_clock::now().time_since_epoch().count();
#endif

const string kami_fi = "kamirulez.inp";
const string kami_fo = "kamirulez.out";
mt19937_64 kami_gen(kami_seed);

long long rand_range(long long rmin, long long rmax) {
	uniform_int_distribution<long long> rdist(rmin, rmax);
	return rdist(kami_gen);
}

long double rand_real(long double rmin, long double rmax) {
	uniform_real_distribution<long double> rdist(rmin, rmax);
	return rdist(kami_gen);
}

void file_io(string fi, string fo) {
	if (fi != "" && (!kami_loc || fi == kami_fi)) {
		freopen(fi.c_str(), "r", stdin);
	}
	if (fo != "" && (!kami_loc || fo == kami_fo)) {
		freopen(fo.c_str(), "w", stdout);
	}
}

void set_up() {
	if (kami_loc) {
		file_io(kami_fi, kami_fo);
	}
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

void just_do_it();

void just_exec_it() {
	if (kami_loc) {
		auto pstart = chrono::steady_clock::now();
		just_do_it();
		auto pend = chrono::steady_clock::now();
		long long ptime = chrono::duration_cast<chrono::milliseconds>(pend - pstart).count();
		string bar(50, '=');
		cout << '\n' << bar << '\n';
		cout << "Time: " << ptime << " ms" << '\n';
	}
	else {
		just_do_it();
	}
}

int main() {
	set_up();
	just_exec_it();
	return 0;
}

// END BOILERPLATE CODE

// BEGIN MAIN CODE

const int ms = 2e2 + 20;
const int inf = 1e9 + 20;
int dp[ms][ms][ms][2];
int X[ms];
int T[ms];

void just_do_it() {
	fill_n(&dp[0][0][0][0], ms * ms * ms * 2, inf);
	int N, L;
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> T[i];
	}
	cin >> L;
	dp[0][0][0][0] = X[0];
	dp[0][0][1][0] = (X[0] <= T[0] ? X[0] : inf);
	dp[N - 1][N - 1][0][0] = L - X[N - 1];
	dp[N - 1][N - 1][1][0] = (L - X[N - 1] <= T[N - 1] ? L - X[N - 1] : inf);
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < N; j++) {
			int lt = j;
			int rt = j + i - 1;
			if (rt >= N) {
				rt -= N;
			}
			for (int k = 0; k <= i; k++) {
				for (int l = 0; l < 2; l++) {
					if (dp[lt][rt][k][l] == inf) {
						continue;
					}
					int cur = (l == 0 ? lt : rt);
					int nl = (lt == 0 ? N - 1 : lt - 1);
					int dl = X[cur] - X[nl];
					if (dl < 0) {
						dl += L;
					}
					dl = min(dl, L - dl);
					dl += dp[lt][rt][k][l];
					int nr = (rt == N - 1 ? 0 : rt + 1);
					int dr = X[cur] - X[nr];
					if (dr < 0) {
						dr += L;
					}
					dr = min(dr, L - dr);
					dr += dp[lt][rt][k][l];;
					dp[nl][rt][k][0] = min(dp[nl][rt][k][0], dl);
					dp[nl][rt][k + 1][0] = min(dp[nl][rt][k + 1][0], (dl <= T[nl] ? dl : inf));
					dp[lt][nr][k][1] = min(dp[lt][nr][k][1], dr);
					dp[lt][nr][k + 1][1] = min(dp[lt][nr][k + 1][1], (dr <= T[nr] ? dr : inf));
				}
			}
		}
	}
	int res = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k <= N; k++) {
				for (int l = 0; l < 2; l++) {
					if (dp[i][j][k][l] != inf) {
						res = max(res, k);
					}
				}
			}
		}
	}
	cout << res;
}

// END MAIN CODE

Compilation message

ho_t3.cpp: In function 'void file_io(std::string, std::string)':
ho_t3.cpp:30:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   freopen(fi.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   freopen(fo.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 83596 KB Output is correct
2 Correct 45 ms 83732 KB Output is correct
3 Correct 39 ms 83656 KB Output is correct
4 Correct 36 ms 83660 KB Output is correct
5 Correct 48 ms 83532 KB Output is correct
6 Correct 50 ms 83648 KB Output is correct
7 Correct 42 ms 83580 KB Output is correct
8 Correct 38 ms 83652 KB Output is correct
9 Correct 49 ms 83676 KB Output is correct
10 Correct 36 ms 83576 KB Output is correct
11 Correct 41 ms 83596 KB Output is correct
12 Correct 36 ms 83648 KB Output is correct
13 Correct 45 ms 83548 KB Output is correct
14 Correct 37 ms 83600 KB Output is correct
15 Correct 37 ms 83552 KB Output is correct
16 Correct 46 ms 83556 KB Output is correct
17 Correct 43 ms 83616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 83596 KB Output is correct
2 Correct 45 ms 83732 KB Output is correct
3 Correct 39 ms 83656 KB Output is correct
4 Correct 36 ms 83660 KB Output is correct
5 Correct 48 ms 83532 KB Output is correct
6 Correct 50 ms 83648 KB Output is correct
7 Correct 42 ms 83580 KB Output is correct
8 Correct 38 ms 83652 KB Output is correct
9 Correct 49 ms 83676 KB Output is correct
10 Correct 36 ms 83576 KB Output is correct
11 Correct 41 ms 83596 KB Output is correct
12 Correct 36 ms 83648 KB Output is correct
13 Correct 45 ms 83548 KB Output is correct
14 Correct 37 ms 83600 KB Output is correct
15 Correct 37 ms 83552 KB Output is correct
16 Correct 46 ms 83556 KB Output is correct
17 Correct 43 ms 83616 KB Output is correct
18 Correct 35 ms 83644 KB Output is correct
19 Correct 49 ms 83548 KB Output is correct
20 Correct 46 ms 83536 KB Output is correct
21 Correct 46 ms 83636 KB Output is correct
22 Correct 45 ms 83532 KB Output is correct
23 Correct 56 ms 83564 KB Output is correct
24 Correct 52 ms 83656 KB Output is correct
25 Correct 43 ms 83608 KB Output is correct
26 Correct 46 ms 83572 KB Output is correct
27 Correct 45 ms 83656 KB Output is correct
28 Correct 40 ms 83620 KB Output is correct
29 Correct 41 ms 83540 KB Output is correct
30 Correct 51 ms 83628 KB Output is correct
31 Correct 41 ms 83604 KB Output is correct
32 Correct 43 ms 83604 KB Output is correct
33 Correct 52 ms 83548 KB Output is correct
34 Correct 40 ms 83652 KB Output is correct
35 Correct 41 ms 83596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 83596 KB Output is correct
2 Correct 45 ms 83732 KB Output is correct
3 Correct 39 ms 83656 KB Output is correct
4 Correct 36 ms 83660 KB Output is correct
5 Correct 48 ms 83532 KB Output is correct
6 Correct 50 ms 83648 KB Output is correct
7 Correct 42 ms 83580 KB Output is correct
8 Correct 38 ms 83652 KB Output is correct
9 Correct 49 ms 83676 KB Output is correct
10 Correct 36 ms 83576 KB Output is correct
11 Correct 41 ms 83596 KB Output is correct
12 Correct 36 ms 83648 KB Output is correct
13 Correct 45 ms 83548 KB Output is correct
14 Correct 37 ms 83600 KB Output is correct
15 Correct 37 ms 83552 KB Output is correct
16 Correct 46 ms 83556 KB Output is correct
17 Correct 43 ms 83616 KB Output is correct
18 Correct 91 ms 83656 KB Output is correct
19 Correct 75 ms 83656 KB Output is correct
20 Correct 59 ms 83624 KB Output is correct
21 Correct 52 ms 83660 KB Output is correct
22 Correct 75 ms 83576 KB Output is correct
23 Correct 51 ms 83620 KB Output is correct
24 Correct 48 ms 83572 KB Output is correct
25 Correct 59 ms 83660 KB Output is correct
26 Correct 45 ms 83652 KB Output is correct
27 Correct 58 ms 83560 KB Output is correct
28 Correct 51 ms 83660 KB Output is correct
29 Correct 60 ms 83660 KB Output is correct
30 Correct 48 ms 83624 KB Output is correct
31 Correct 52 ms 83604 KB Output is correct
32 Correct 47 ms 83564 KB Output is correct
33 Correct 51 ms 83548 KB Output is correct
34 Correct 53 ms 83588 KB Output is correct
35 Correct 43 ms 83532 KB Output is correct
36 Correct 43 ms 83628 KB Output is correct
37 Correct 49 ms 83628 KB Output is correct
38 Correct 39 ms 83656 KB Output is correct
39 Correct 47 ms 83564 KB Output is correct
40 Correct 40 ms 83660 KB Output is correct
41 Correct 105 ms 83652 KB Output is correct
42 Correct 57 ms 83644 KB Output is correct
43 Correct 81 ms 83624 KB Output is correct
44 Correct 59 ms 83656 KB Output is correct
45 Correct 97 ms 83632 KB Output is correct
46 Correct 66 ms 83632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 83596 KB Output is correct
2 Correct 45 ms 83732 KB Output is correct
3 Correct 39 ms 83656 KB Output is correct
4 Correct 36 ms 83660 KB Output is correct
5 Correct 48 ms 83532 KB Output is correct
6 Correct 50 ms 83648 KB Output is correct
7 Correct 42 ms 83580 KB Output is correct
8 Correct 38 ms 83652 KB Output is correct
9 Correct 49 ms 83676 KB Output is correct
10 Correct 36 ms 83576 KB Output is correct
11 Correct 41 ms 83596 KB Output is correct
12 Correct 36 ms 83648 KB Output is correct
13 Correct 45 ms 83548 KB Output is correct
14 Correct 37 ms 83600 KB Output is correct
15 Correct 37 ms 83552 KB Output is correct
16 Correct 46 ms 83556 KB Output is correct
17 Correct 43 ms 83616 KB Output is correct
18 Correct 35 ms 83644 KB Output is correct
19 Correct 49 ms 83548 KB Output is correct
20 Correct 46 ms 83536 KB Output is correct
21 Correct 46 ms 83636 KB Output is correct
22 Correct 45 ms 83532 KB Output is correct
23 Correct 56 ms 83564 KB Output is correct
24 Correct 52 ms 83656 KB Output is correct
25 Correct 43 ms 83608 KB Output is correct
26 Correct 46 ms 83572 KB Output is correct
27 Correct 45 ms 83656 KB Output is correct
28 Correct 40 ms 83620 KB Output is correct
29 Correct 41 ms 83540 KB Output is correct
30 Correct 51 ms 83628 KB Output is correct
31 Correct 41 ms 83604 KB Output is correct
32 Correct 43 ms 83604 KB Output is correct
33 Correct 52 ms 83548 KB Output is correct
34 Correct 40 ms 83652 KB Output is correct
35 Correct 41 ms 83596 KB Output is correct
36 Correct 91 ms 83656 KB Output is correct
37 Correct 75 ms 83656 KB Output is correct
38 Correct 59 ms 83624 KB Output is correct
39 Correct 52 ms 83660 KB Output is correct
40 Correct 75 ms 83576 KB Output is correct
41 Correct 51 ms 83620 KB Output is correct
42 Correct 48 ms 83572 KB Output is correct
43 Correct 59 ms 83660 KB Output is correct
44 Correct 45 ms 83652 KB Output is correct
45 Correct 58 ms 83560 KB Output is correct
46 Correct 51 ms 83660 KB Output is correct
47 Correct 60 ms 83660 KB Output is correct
48 Correct 48 ms 83624 KB Output is correct
49 Correct 52 ms 83604 KB Output is correct
50 Correct 47 ms 83564 KB Output is correct
51 Correct 51 ms 83548 KB Output is correct
52 Correct 53 ms 83588 KB Output is correct
53 Correct 43 ms 83532 KB Output is correct
54 Correct 43 ms 83628 KB Output is correct
55 Correct 49 ms 83628 KB Output is correct
56 Correct 39 ms 83656 KB Output is correct
57 Correct 47 ms 83564 KB Output is correct
58 Correct 40 ms 83660 KB Output is correct
59 Correct 105 ms 83652 KB Output is correct
60 Correct 57 ms 83644 KB Output is correct
61 Correct 81 ms 83624 KB Output is correct
62 Correct 59 ms 83656 KB Output is correct
63 Correct 97 ms 83632 KB Output is correct
64 Correct 66 ms 83632 KB Output is correct
65 Correct 69 ms 83660 KB Output is correct
66 Correct 74 ms 83668 KB Output is correct
67 Correct 70 ms 83760 KB Output is correct
68 Correct 79 ms 83764 KB Output is correct
69 Correct 101 ms 83660 KB Output is correct
70 Correct 83 ms 83656 KB Output is correct
71 Correct 77 ms 83656 KB Output is correct
72 Correct 78 ms 83544 KB Output is correct
73 Correct 69 ms 83640 KB Output is correct
74 Correct 81 ms 83656 KB Output is correct
75 Correct 68 ms 83656 KB Output is correct
76 Correct 86 ms 83660 KB Output is correct
77 Correct 69 ms 83544 KB Output is correct
78 Correct 77 ms 83656 KB Output is correct
79 Correct 63 ms 83656 KB Output is correct
80 Correct 89 ms 83664 KB Output is correct
81 Correct 62 ms 83668 KB Output is correct
82 Correct 68 ms 83664 KB Output is correct
83 Correct 82 ms 83656 KB Output is correct
84 Correct 75 ms 83584 KB Output is correct
85 Correct 71 ms 83660 KB Output is correct
86 Correct 73 ms 83652 KB Output is correct
87 Correct 98 ms 83656 KB Output is correct
88 Correct 84 ms 83656 KB Output is correct
89 Correct 72 ms 83660 KB Output is correct
90 Correct 61 ms 83660 KB Output is correct
91 Correct 88 ms 83556 KB Output is correct
92 Correct 75 ms 83656 KB Output is correct
93 Correct 72 ms 83640 KB Output is correct