Submission #799282

# Submission time Handle Problem Language Result Execution time Memory
799282 2023-07-31T11:44:05 Z LittleCube Ancient Books (IOI17_books) C++17
22 / 100
701 ms 24824 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include "books.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

int n, dp[1005][1005], rp[1005], l, r, range[1005][2];

long long minimum_walk(std::vector<int> p, int s)
{
	n = p.size();
	l = 0, r = n - 1;
	while (l < n && p[l] == l)
		l++;
	if (l == n)
		return 0;
	while (r && p[r] == r)
		r--;

	ll ans = 0;
	if (s < l)
	{
		ans += 2 * (l - s);
		s = l;
	}
	if (r < s)
	{
		ans += 2 * (s - r);
		s = r;
	}
	for (int i = 0; i < n; i++)
		ans += abs(p[i] - i);
	for (int i = 0; i < n; i++)
		rp[p[i]] = i;

	cerr << "calc n\n";
	// calc n

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			dp[i][j] = 1e9;
	dp[s][s] = 0;
	for (int i = 0; i < n; i++)
		range[i][0] = min({i, p[i], rp[i]}), range[i][1] = max({i, p[i], rp[i]});
	for (int i = 0; i < n; i++)
		for (int j = i; j < n; j++)
			for (int k = i; k <= j; k++)
			{
				dp[min(i, range[k][0])][max(j, range[k][1])] = min(dp[min(i, range[k][0])][max(j, range[k][1])], dp[i][j]);
				if (j < n)
					dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 2);
				if (i)
					dp[i - 1][j] = min(dp[i - 1][j], dp[i][j] + 2);
			}

	return ans + dp[l][r];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 572 ms 4244 KB Output is correct
20 Correct 573 ms 4244 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 692 ms 4300 KB Output is correct
23 Correct 679 ms 4248 KB Output is correct
24 Correct 686 ms 4272 KB Output is correct
25 Correct 679 ms 4244 KB Output is correct
26 Correct 668 ms 4248 KB Output is correct
27 Correct 666 ms 4180 KB Output is correct
28 Correct 654 ms 4244 KB Output is correct
29 Correct 654 ms 4244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 572 ms 4244 KB Output is correct
20 Correct 573 ms 4244 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 692 ms 4300 KB Output is correct
23 Correct 679 ms 4248 KB Output is correct
24 Correct 686 ms 4272 KB Output is correct
25 Correct 679 ms 4244 KB Output is correct
26 Correct 668 ms 4248 KB Output is correct
27 Correct 666 ms 4180 KB Output is correct
28 Correct 654 ms 4244 KB Output is correct
29 Correct 654 ms 4244 KB Output is correct
30 Runtime error 112 ms 24824 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 701 ms 4244 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 572 ms 4244 KB Output is correct
20 Correct 573 ms 4244 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 692 ms 4300 KB Output is correct
23 Correct 679 ms 4248 KB Output is correct
24 Correct 686 ms 4272 KB Output is correct
25 Correct 679 ms 4244 KB Output is correct
26 Correct 668 ms 4248 KB Output is correct
27 Correct 666 ms 4180 KB Output is correct
28 Correct 654 ms 4244 KB Output is correct
29 Correct 654 ms 4244 KB Output is correct
30 Runtime error 112 ms 24824 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -