답안 #833702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833702 2023-08-22T08:02:16 Z caganyanmaz 고대 책들 (IOI17_books) C++17
50 / 100
109 ms 35704 KB
#include <bits/stdc++.h>
#define pb push_back
#include "books.h"
#define ll long long 
using namespace std;

//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif

struct Node
{
	int head, tail, size, nxt;
	Node(int i) : head(i), tail(i), size(1), nxt(-1) {}
	Node() : Node(-1) {}

};

constexpr static int MXN = 1e6;
Node node[MXN];
bitset<MXN> visited;
bitset<MXN> visited_component;

void merge(int a, int b);

ll minimum_walk(vector<int> p, int s) 
{
	int n = p.size();
	ll sum = 0;
	int current = 0;
	vector<int> rp(n);
	for (int i = 0; i < n; i++)
		rp[p[i]] = i;
	vector<int> pp;
	int spos = MXN;
	int epos = -1;
	vector<int> v;
	debug(p, rp);
	vector<int> possibilities;
	for (int i = 0; i < n-1; i++)
	{

		if (p[i] > i)
			current++;
		if (rp[i] < i)
			current--;
		if (p[i] != i)
			possibilities.pb(i);
		if (current > 0)
		{
			spos = min(spos, i);
			epos = max(epos, i+1);
		}
		debug(current, i);
		sum += current * 2;
		v.pb(current);
	}
	if (sum == 0)
		return sum;

	for (int i = spos; i < epos; i++)
	{
		if (v[i] == 0)
			sum += 2;
	}
	debug(spos, epos, sum);

	int a = upper_bound(possibilities.begin(), possibilities.end(), s) - possibilities.begin();
	int first_cost = MXN;
	if (a < n)
		first_cost = min(first_cost, possibilities[a] - s);
	a--;
	if (a >= 0)
		first_cost = min(first_cost, s - possibilities[a]);
	return sum + first_cost * 2;


}

void merge(int a, int b)
{
	if (node[a].size < node[b].size) swap(a, b);
	node[a].size += node[b].size;
	node[node[a].tail].nxt = b;
	node[a].tail = node[b].tail;
	for (;b!=-1;b=node[b].nxt)
		node[b].head = a;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Correct 7 ms 15956 KB Output is correct
3 Correct 7 ms 15956 KB Output is correct
4 Correct 9 ms 15956 KB Output is correct
5 Correct 7 ms 15956 KB Output is correct
6 Correct 7 ms 15956 KB Output is correct
7 Correct 7 ms 15956 KB Output is correct
8 Correct 7 ms 15956 KB Output is correct
9 Correct 7 ms 15956 KB Output is correct
10 Correct 7 ms 15956 KB Output is correct
11 Correct 9 ms 15956 KB Output is correct
12 Correct 7 ms 15864 KB Output is correct
13 Correct 7 ms 15944 KB Output is correct
14 Correct 7 ms 15956 KB Output is correct
15 Correct 7 ms 15856 KB Output is correct
16 Correct 7 ms 15956 KB Output is correct
17 Correct 7 ms 15956 KB Output is correct
18 Correct 7 ms 15956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Correct 7 ms 15956 KB Output is correct
3 Correct 7 ms 15956 KB Output is correct
4 Correct 9 ms 15956 KB Output is correct
5 Correct 7 ms 15956 KB Output is correct
6 Correct 7 ms 15956 KB Output is correct
7 Correct 7 ms 15956 KB Output is correct
8 Correct 7 ms 15956 KB Output is correct
9 Correct 7 ms 15956 KB Output is correct
10 Correct 7 ms 15956 KB Output is correct
11 Correct 9 ms 15956 KB Output is correct
12 Correct 7 ms 15864 KB Output is correct
13 Correct 7 ms 15944 KB Output is correct
14 Correct 7 ms 15956 KB Output is correct
15 Correct 7 ms 15856 KB Output is correct
16 Correct 7 ms 15956 KB Output is correct
17 Correct 7 ms 15956 KB Output is correct
18 Correct 7 ms 15956 KB Output is correct
19 Correct 7 ms 15956 KB Output is correct
20 Correct 7 ms 15956 KB Output is correct
21 Correct 7 ms 15948 KB Output is correct
22 Correct 7 ms 15956 KB Output is correct
23 Correct 7 ms 15956 KB Output is correct
24 Correct 7 ms 15872 KB Output is correct
25 Correct 7 ms 15872 KB Output is correct
26 Correct 9 ms 15960 KB Output is correct
27 Correct 7 ms 15912 KB Output is correct
28 Correct 7 ms 15956 KB Output is correct
29 Correct 7 ms 15956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Correct 7 ms 15956 KB Output is correct
3 Correct 7 ms 15956 KB Output is correct
4 Correct 9 ms 15956 KB Output is correct
5 Correct 7 ms 15956 KB Output is correct
6 Correct 7 ms 15956 KB Output is correct
7 Correct 7 ms 15956 KB Output is correct
8 Correct 7 ms 15956 KB Output is correct
9 Correct 7 ms 15956 KB Output is correct
10 Correct 7 ms 15956 KB Output is correct
11 Correct 9 ms 15956 KB Output is correct
12 Correct 7 ms 15864 KB Output is correct
13 Correct 7 ms 15944 KB Output is correct
14 Correct 7 ms 15956 KB Output is correct
15 Correct 7 ms 15856 KB Output is correct
16 Correct 7 ms 15956 KB Output is correct
17 Correct 7 ms 15956 KB Output is correct
18 Correct 7 ms 15956 KB Output is correct
19 Correct 7 ms 15956 KB Output is correct
20 Correct 7 ms 15956 KB Output is correct
21 Correct 7 ms 15948 KB Output is correct
22 Correct 7 ms 15956 KB Output is correct
23 Correct 7 ms 15956 KB Output is correct
24 Correct 7 ms 15872 KB Output is correct
25 Correct 7 ms 15872 KB Output is correct
26 Correct 9 ms 15960 KB Output is correct
27 Correct 7 ms 15912 KB Output is correct
28 Correct 7 ms 15956 KB Output is correct
29 Correct 7 ms 15956 KB Output is correct
30 Correct 104 ms 35676 KB Output is correct
31 Correct 95 ms 35700 KB Output is correct
32 Correct 82 ms 31884 KB Output is correct
33 Correct 89 ms 33668 KB Output is correct
34 Correct 89 ms 33668 KB Output is correct
35 Correct 109 ms 35060 KB Output is correct
36 Correct 96 ms 35288 KB Output is correct
37 Correct 92 ms 35624 KB Output is correct
38 Correct 91 ms 35704 KB Output is correct
39 Correct 92 ms 35700 KB Output is correct
40 Correct 100 ms 35616 KB Output is correct
41 Correct 92 ms 35632 KB Output is correct
42 Correct 91 ms 35700 KB Output is correct
43 Correct 89 ms 33788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 15956 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Correct 7 ms 15956 KB Output is correct
3 Correct 7 ms 15956 KB Output is correct
4 Correct 9 ms 15956 KB Output is correct
5 Correct 7 ms 15956 KB Output is correct
6 Correct 7 ms 15956 KB Output is correct
7 Correct 7 ms 15956 KB Output is correct
8 Correct 7 ms 15956 KB Output is correct
9 Correct 7 ms 15956 KB Output is correct
10 Correct 7 ms 15956 KB Output is correct
11 Correct 9 ms 15956 KB Output is correct
12 Correct 7 ms 15864 KB Output is correct
13 Correct 7 ms 15944 KB Output is correct
14 Correct 7 ms 15956 KB Output is correct
15 Correct 7 ms 15856 KB Output is correct
16 Correct 7 ms 15956 KB Output is correct
17 Correct 7 ms 15956 KB Output is correct
18 Correct 7 ms 15956 KB Output is correct
19 Correct 7 ms 15956 KB Output is correct
20 Correct 7 ms 15956 KB Output is correct
21 Correct 7 ms 15948 KB Output is correct
22 Correct 7 ms 15956 KB Output is correct
23 Correct 7 ms 15956 KB Output is correct
24 Correct 7 ms 15872 KB Output is correct
25 Correct 7 ms 15872 KB Output is correct
26 Correct 9 ms 15960 KB Output is correct
27 Correct 7 ms 15912 KB Output is correct
28 Correct 7 ms 15956 KB Output is correct
29 Correct 7 ms 15956 KB Output is correct
30 Correct 104 ms 35676 KB Output is correct
31 Correct 95 ms 35700 KB Output is correct
32 Correct 82 ms 31884 KB Output is correct
33 Correct 89 ms 33668 KB Output is correct
34 Correct 89 ms 33668 KB Output is correct
35 Correct 109 ms 35060 KB Output is correct
36 Correct 96 ms 35288 KB Output is correct
37 Correct 92 ms 35624 KB Output is correct
38 Correct 91 ms 35704 KB Output is correct
39 Correct 92 ms 35700 KB Output is correct
40 Correct 100 ms 35616 KB Output is correct
41 Correct 92 ms 35632 KB Output is correct
42 Correct 91 ms 35700 KB Output is correct
43 Correct 89 ms 33788 KB Output is correct
44 Incorrect 7 ms 15956 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -