답안 #798993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798993 2023-07-31T08:30:37 Z LittleCube 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 212 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';
		}
	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; i >= 0; i--)
		left[i] = min(left[i], left[i + 1]);
	for (int i = s; i < n; i++)
		left[i] = i - left[i];
	return ans + 2 * *min_element(left.begin() + s, left.begin() + n);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4728'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 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 -