답안 #748874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748874 2023-05-27T05:59:41 Z wenqi 고대 책들 (IOI17_books) C++17
0 / 100
0 ms 212 KB
#include "books.h"
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <set>

using namespace std;
using ll = long long;

bool seen[1000005];
vector<int> P;
vector<int> t;

ll dfs(int i)
{
	if (seen[i])
		return 0;
	seen[i] = true;
	t.push_back(i);
	return abs(i - P[i]) + dfs(P[i]);
}

ll minimum_walk(vector<int> p, int s)
{
	P = p;
	ll sum = 0;
	int n = p.size();
	vector<pair<int, int>> q;
	q.push_back({s, s});
	bool lol = false;
	for (int i = 0; i < n; i++)
	{
		if (seen[i] or i == p[i])
			continue;
		t.clear();
		sum += dfs(i);
		sort(t.begin(), t.end());
		q.push_back({t.front(), t.back()});
		auto [a, b] = q.back();
		if (a <= s and s <= b)
			lol = true;
	}
	sort(q.begin(), q.end());
	int lt = -1;
	for (auto [a, b] : q)
	{
		if (lt == -1)
		{
			lt = b;
		}
		if (a > lt)
		{
			sum += 2 * (a - lt);
			lt = b;
		}
		else
		{
			lt = max(lt, b);
		}
	}
	int mn = 1e9;
	for (int i = 0; i < n; i++)
		if (seen[i])
			mn = min(mn, abs(i - s));
	if (lol)
		sum += 69;
	return sum;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '77'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '77'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '77'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2813'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '77'
4 Halted 0 ms 0 KB -