답안 #427451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427451 2021-06-14T15:30:36 Z Tangent 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 204 KB
#include "books.h"
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;

#define ffor(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define fford(i, a, b) for (ll i = (a); i > (ll)(b); i--)
#define rep(i, n) ffor(i, 0, n)
#define forin(x, a) for (auto &x: a)
#define all(a) a.begin(), a.end()

long long minimum_walk(std::vector<int> p, int s) {
	int n = p.size();
	vii seen(n);
	vpii segs;
	ll res = 0;
	rep(i, n) {
		if (!seen[i]) {
			seen[i] = true;
			int lo = i, hi = i;
			res += abs(p[i] - i);
			int curr = p[i];
			while (curr != i) {
				lo = min(lo, curr);
				hi = max(hi, curr);
				seen[curr] = true;
				res += abs(curr - p[curr]);
				curr = p[curr];
			}
			// if (lo != hi)
			segs.emplace_back(lo, hi + 1);
		}
	}
	sort(all(segs));
	reverse(all(segs));
	if (segs.empty()) return res;
	vpii merged = {segs.back()};
	segs.pop_back();
	while (!segs.empty()) {
		if (segs.back().first < merged.back().second) {
			merged.back().second = max(merged.back().second, segs.back().second);
		} else {
			merged.emplace_back(segs.back());
		}
		segs.pop_back();
	}
	rep(i, merged.size() - 1) {
		res += 2 * (merged[i + 1].first - merged[i].second + 1);
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -