Submission #1061682

# Submission time Handle Problem Language Result Execution time Memory
1061682 2024-08-16T11:49:22 Z fv3 Ancient Books (IOI17_books) C++14
12 / 100
2000 ms 3536 KB
#include "books.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int N, S;
vector<int> P;

ll res = 0;

int l, r;
void trim_edges()
{
	while (P[l] == l && l < N)
		l++;
	while (P[r] == r && r >= 0)
		r--;
}

int cur = 0;
int go_right(int index)
{
	for (int i = index; i < r; i++)
	{
		if (P[i] > cur)
			swap(P[i], cur);
	}
	swap(cur, P[r]);

	res += r - index;
	index = r;
	trim_edges();

	return index;
}

int go_left(int index)
{
	res += index - r;
	index = r;
	while (cur == r && r > 0)
		swap(cur, P[r--]);

	int pos = r;
	for (; P[pos] != r; pos--)
	{
		if (cur > P[pos])
			swap(P[pos], cur);
	}


	res += index - pos;
	trim_edges();

	return pos;
}

ll minimum_walk(vector<int> p_, int s_) 
{
	P = p_;	S = s_;
	N = P.size();	

	l = 0, r = N - 1;
	trim_edges();
	if (l == N) return 0;

	res = l;

	int index = l;
	for (int t = 0; t < N && l <= r; t++)
	{
		if ((t&1) == 0)
			index = go_right(index);
		else
			index = go_left(index);

		cerr << '\n' << res << ": (" << l << ", " << r << ")\n";
		for (auto p : P)
			cerr << p << ' ';
		cerr << '\n';
		for (int i = 0; i < N; i++)
			cerr << (i == index ? '^' : ' ') << ' ';
		cerr << '\n';
	}

	res += index;
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 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 1 ms 348 KB Output is correct
10 Correct 0 ms 344 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 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 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 1 ms 348 KB Output is correct
10 Correct 0 ms 344 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 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Execution timed out 2065 ms 3536 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 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 1 ms 348 KB Output is correct
10 Correct 0 ms 344 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 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Execution timed out 2065 ms 3536 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2043 ms 3188 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 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 1 ms 348 KB Output is correct
10 Correct 0 ms 344 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 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Execution timed out 2065 ms 3536 KB Time limit exceeded
20 Halted 0 ms 0 KB -