Submission #799003

# Submission time Handle Problem Language Result Execution time Memory
799003 2023-07-31T08:35:21 Z LittleCube Ancient Books (IOI17_books) C++17
0 / 100
1 ms 300 KB
#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;

long long minimum_walk(std::vector<int> p, int s)
{
	int n = p.size();
	vector<int> vis(n, 0);

	ll ans = 0;
	for (int i = 0; i < n; i++)
		ans += abs(p[i] - i);
	vector<pii> why;
	for (int i = 0; i < n; i++)
		if (!vis[i])
		{
			vector<int> v;
			v.emplace_back(i);
			vis[i] = 1;
			while (!vis[p[v.back()]])
			{
				v.emplace_back(p[v.back()]);
				vis[v.back()] = 1;
			}
			if (v.size() == 1)
				continue;
			int l = -1e9, r = n - 1;
			for (auto j : v)
			{
				if (j <= s)
					l = max(l, j);
				if (j >= s)
					r = min(r, j);
			}
			why.emplace_back(pii(l, r));
			// cerr << l << ' ' << r << '\n';
		}
	// cerr << ans << '\n';
	vector<int> left(n + 1, s);
	for (auto [l, r] : why)
		if (r > s)
			left[r - 1] = min(left[r - 1], l);
	for (int i = n - 1; i >= 0; i--)
		left[i] = min(left[i], left[i + 1]);
	// for (int i : left)
	// 	cerr << i << ' ';
	// cerr << '\n';
	for (int i = s; i < n; i++)
		left[i] = i - left[i];
	return ans + 2 * *min_element(left.begin() + s, left.begin() + n);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 300 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3892'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -