Submission #446990

# Submission time Handle Problem Language Result Execution time Memory
446990 2021-07-24T07:55:12 Z maomao90 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
208 ms 300240 KB
#include <bits/stdc++.h> 
using namespace std;

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#ifdef DEBUG
#define debug(args...) _debug(args)
void _debug(const char* format, ...) {
	va_list args;
	va_start(args, format);
	vprintf(format, args);
	va_end(args);
}
#else
#define debug(args...)
#endif

#define INF 2000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 205

int n, l;
ll x[MAXN], t[MAXN];
ll dp[MAXN][MAXN][5][MAXN];
int ans;

int main() {
	scanf("%d%d", &n, &l);
	REP (i, 1, n + 1) {
		scanf("%lld", &x[i]);
	}
	REP (i, 1, n + 1) {
		scanf("%lld", &t[i]);
	}
	x[0] = 0;
	t[0] = -1;
	n++;
	REP (i, 0, n + 3) {
		REP (j, 0, n + 3) {
			REP (m, 0, 2) {
				REP (k, 0, n + 3) {
					dp[i][j][m][k] = LINF;
				}
			}
		}
	}
	dp[0][0][0][0] = dp[0][0][1][0] = 0;
	// dp[i][j][m][k] is with range from s to e and currently at s,
	// minimum time to take k stamps
	// i is the length, j is starting point, m is positive or negative
	REP (i, 1, n) {
		REP (j, 0, n) {
			REP (m, 0, 2) {
				int p = m ? 1 : -1;
				int s = j, e = (j + i * p + n) % n;
				REP (k, 0, n) {
					int pk = k;
					ll pc = min(abs(x[s] - x[(s + p + n) % n]), 
							min(abs(x[s] - x[(s + p + n) % n] - l), 
								abs(x[s] - x[(s + p + n) % n] + l)));
					debug(" %lld %lld\n", x[s] - x[(s + p + n) % n], pc);
					if (k != 0 && dp[i - 1][(j + p + n) % n][m][k - 1] + pc <= t[s]) {
					   pk--;
					}
					mnto(dp[i][j][m][k], dp[i - 1][(j + p + n) % n][m][pk] + pc);
					int ppk = k;
					ll ppc = min(abs(x[e] - x[s]), 
							min(abs(x[e] - x[s] - l), 
								abs(x[e] - x[s] + l)));
					debug(" %lld %lld\n", x[e] - x[s], ppc);
					if (k != 0 && dp[i - 1][e][!m][k - 1] + ppc <= t[s]) {
					   ppk--;
					}
					mnto(dp[i][j][m][k], dp[i - 1][e][!m][ppk] + ppc);
					debug("%d %d %d %d: %lld\n", s, e, p, k, dp[i][j][m][k]);
					if (dp[i][j][m][k] < LINF) {
						mxto(ans, k);
					}
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  scanf("%d%d", &n, &l);
      |  ~~~~~^~~~~~~~~~~~~~~~
ho_t3.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   scanf("%lld", &x[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
ho_t3.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |   scanf("%lld", &t[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 1320 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 1868 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1868 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 1868 KB Output is correct
13 Correct 1 ms 1868 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1836 KB Output is correct
17 Correct 1 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 1320 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 1868 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1868 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 1868 KB Output is correct
13 Correct 1 ms 1868 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1836 KB Output is correct
17 Correct 1 ms 1868 KB Output is correct
18 Correct 1 ms 2252 KB Output is correct
19 Correct 1 ms 1484 KB Output is correct
20 Correct 1 ms 1868 KB Output is correct
21 Correct 1 ms 2252 KB Output is correct
22 Correct 1 ms 1356 KB Output is correct
23 Correct 2 ms 2508 KB Output is correct
24 Correct 1 ms 2124 KB Output is correct
25 Correct 1 ms 2252 KB Output is correct
26 Correct 1 ms 2252 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 1 ms 1320 KB Output is correct
29 Correct 2 ms 2508 KB Output is correct
30 Correct 2 ms 2508 KB Output is correct
31 Correct 1 ms 2252 KB Output is correct
32 Correct 2 ms 2124 KB Output is correct
33 Correct 1 ms 2508 KB Output is correct
34 Correct 2 ms 2508 KB Output is correct
35 Correct 1 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 1320 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 1868 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1868 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 1868 KB Output is correct
13 Correct 1 ms 1868 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1836 KB Output is correct
17 Correct 1 ms 1868 KB Output is correct
18 Correct 146 ms 236284 KB Output is correct
19 Correct 96 ms 136900 KB Output is correct
20 Correct 47 ms 71192 KB Output is correct
21 Correct 76 ms 129388 KB Output is correct
22 Correct 98 ms 169220 KB Output is correct
23 Correct 35 ms 60672 KB Output is correct
24 Correct 26 ms 46740 KB Output is correct
25 Correct 33 ms 59136 KB Output is correct
26 Correct 13 ms 21324 KB Output is correct
27 Correct 37 ms 61680 KB Output is correct
28 Correct 25 ms 43292 KB Output is correct
29 Correct 36 ms 63172 KB Output is correct
30 Correct 27 ms 49164 KB Output is correct
31 Correct 33 ms 59084 KB Output is correct
32 Correct 17 ms 29864 KB Output is correct
33 Correct 34 ms 59068 KB Output is correct
34 Correct 12 ms 19884 KB Output is correct
35 Correct 33 ms 57664 KB Output is correct
36 Correct 15 ms 26284 KB Output is correct
37 Correct 38 ms 61652 KB Output is correct
38 Correct 18 ms 32716 KB Output is correct
39 Correct 36 ms 64312 KB Output is correct
40 Correct 21 ms 37000 KB Output is correct
41 Correct 203 ms 296924 KB Output is correct
42 Correct 116 ms 192048 KB Output is correct
43 Correct 193 ms 296936 KB Output is correct
44 Correct 118 ms 189380 KB Output is correct
45 Correct 189 ms 296924 KB Output is correct
46 Correct 115 ms 191908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 1320 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 1868 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1868 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 1868 KB Output is correct
13 Correct 1 ms 1868 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1836 KB Output is correct
17 Correct 1 ms 1868 KB Output is correct
18 Correct 1 ms 2252 KB Output is correct
19 Correct 1 ms 1484 KB Output is correct
20 Correct 1 ms 1868 KB Output is correct
21 Correct 1 ms 2252 KB Output is correct
22 Correct 1 ms 1356 KB Output is correct
23 Correct 2 ms 2508 KB Output is correct
24 Correct 1 ms 2124 KB Output is correct
25 Correct 1 ms 2252 KB Output is correct
26 Correct 1 ms 2252 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 1 ms 1320 KB Output is correct
29 Correct 2 ms 2508 KB Output is correct
30 Correct 2 ms 2508 KB Output is correct
31 Correct 1 ms 2252 KB Output is correct
32 Correct 2 ms 2124 KB Output is correct
33 Correct 1 ms 2508 KB Output is correct
34 Correct 2 ms 2508 KB Output is correct
35 Correct 1 ms 2508 KB Output is correct
36 Correct 146 ms 236284 KB Output is correct
37 Correct 96 ms 136900 KB Output is correct
38 Correct 47 ms 71192 KB Output is correct
39 Correct 76 ms 129388 KB Output is correct
40 Correct 98 ms 169220 KB Output is correct
41 Correct 35 ms 60672 KB Output is correct
42 Correct 26 ms 46740 KB Output is correct
43 Correct 33 ms 59136 KB Output is correct
44 Correct 13 ms 21324 KB Output is correct
45 Correct 37 ms 61680 KB Output is correct
46 Correct 25 ms 43292 KB Output is correct
47 Correct 36 ms 63172 KB Output is correct
48 Correct 27 ms 49164 KB Output is correct
49 Correct 33 ms 59084 KB Output is correct
50 Correct 17 ms 29864 KB Output is correct
51 Correct 34 ms 59068 KB Output is correct
52 Correct 12 ms 19884 KB Output is correct
53 Correct 33 ms 57664 KB Output is correct
54 Correct 15 ms 26284 KB Output is correct
55 Correct 38 ms 61652 KB Output is correct
56 Correct 18 ms 32716 KB Output is correct
57 Correct 36 ms 64312 KB Output is correct
58 Correct 21 ms 37000 KB Output is correct
59 Correct 203 ms 296924 KB Output is correct
60 Correct 116 ms 192048 KB Output is correct
61 Correct 193 ms 296936 KB Output is correct
62 Correct 118 ms 189380 KB Output is correct
63 Correct 189 ms 296924 KB Output is correct
64 Correct 115 ms 191908 KB Output is correct
65 Correct 161 ms 265920 KB Output is correct
66 Correct 155 ms 242068 KB Output is correct
67 Correct 147 ms 230588 KB Output is correct
68 Correct 135 ms 211016 KB Output is correct
69 Correct 162 ms 262788 KB Output is correct
70 Correct 156 ms 251004 KB Output is correct
71 Correct 162 ms 254036 KB Output is correct
72 Correct 159 ms 256964 KB Output is correct
73 Correct 150 ms 236192 KB Output is correct
74 Correct 138 ms 219040 KB Output is correct
75 Correct 157 ms 245152 KB Output is correct
76 Correct 183 ms 284216 KB Output is correct
77 Correct 183 ms 284304 KB Output is correct
78 Correct 131 ms 213424 KB Output is correct
79 Correct 140 ms 221920 KB Output is correct
80 Correct 172 ms 277808 KB Output is correct
81 Correct 135 ms 224964 KB Output is correct
82 Correct 147 ms 239276 KB Output is correct
83 Correct 197 ms 296928 KB Output is correct
84 Correct 153 ms 250948 KB Output is correct
85 Correct 172 ms 275004 KB Output is correct
86 Correct 169 ms 269000 KB Output is correct
87 Correct 151 ms 245124 KB Output is correct
88 Correct 208 ms 300140 KB Output is correct
89 Correct 204 ms 300224 KB Output is correct
90 Correct 159 ms 248024 KB Output is correct
91 Correct 187 ms 300240 KB Output is correct
92 Correct 187 ms 300192 KB Output is correct
93 Correct 184 ms 293540 KB Output is correct