Submission #137686

# Submission time Handle Problem Language Result Execution time Memory
137686 2019-07-28T08:33:40 Z random0029 Ancient Books (IOI17_books) C++14
50 / 100
211 ms 23008 KB
// ItnoE
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000006;
int n, M[N], A[N];
int64_t minimum_walk(vector < int > P, int st)
{
	n = (int)P.size();
	ll SM = 0;
	for (int i = 0; i < n; i ++)
		SM += abs(P[i] - i);
	vector < pair < int , int > > cyc;
	for (int i = 0; i < n; i ++)
		if (!M[i] && P[i] != i)
		{
			int v = i;
			int Mx = -N * 2, Mn = N * 2;
			while (!M[v])
			{
				M[v] = 1;
				Mn = min(Mn, v);
				Mx = max(Mx, v);
				v = P[v];
			}
			A[Mn] = max(A[Mn], Mx);
			cyc.push_back({Mn, Mx});
		}
	if (SM == 0)
		return (SM);
	//bool fail = 1;
	int Mx = 0, last = -1;
	vector < pair < int , int > > vec;
	for (int i = 0; i < n; i ++)
	{
		Mx = max({Mx, A[i], i});
		if (P[i] != i && last == -1)
			last = i;
		if (P[i] == i)
			continue;
		if (Mx == i)
			vec.push_back({last, Mx}), last = -1;
		//if (i <= st && st <= Mx)
			//fail = 0;
	}
	if (P[st] == st)
	{
		int le = st, ri = st;
		while (le >= 0 && P[le] == le)
			le --;
		while (ri < n && P[ri] == ri)
			ri ++;
		if (le == -1) le ++;
		if (ri == n) ri --;
		SM += (ri - le) * 2;
	}
	if (st != 0 && P[st] != st)
	{
		pair < int , int > X;
		for (auto Y : vec)
			if (Y.first <= st && st <= Y.second)
				X = Y;
		int cnt = 0;
		for (auto Y : cyc)
			if (X.first <= Y.first && Y.second <= X.second)
				cnt ++;
		return (cnt);
	}
	for (int i = 1; i < (int)vec.size(); i ++)
	{
		SM += (vec[i].first - vec[i - 1].second) * 2;
		assert(vec[i].first > vec[i - 1].second);
	}
	return (SM);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 424 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 424 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 424 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 211 ms 14468 KB Output is correct
31 Correct 208 ms 14492 KB Output is correct
32 Correct 136 ms 10500 KB Output is correct
33 Correct 164 ms 22884 KB Output is correct
34 Correct 163 ms 22884 KB Output is correct
35 Correct 167 ms 23008 KB Output is correct
36 Correct 162 ms 21224 KB Output is correct
37 Correct 157 ms 18676 KB Output is correct
38 Correct 160 ms 17612 KB Output is correct
39 Correct 161 ms 17400 KB Output is correct
40 Correct 172 ms 15224 KB Output is correct
41 Correct 202 ms 14584 KB Output is correct
42 Correct 186 ms 14684 KB Output is correct
43 Correct 165 ms 20416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB 3rd lines differ - on the 1st token, expected: '3304', found: '182'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 424 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 211 ms 14468 KB Output is correct
31 Correct 208 ms 14492 KB Output is correct
32 Correct 136 ms 10500 KB Output is correct
33 Correct 164 ms 22884 KB Output is correct
34 Correct 163 ms 22884 KB Output is correct
35 Correct 167 ms 23008 KB Output is correct
36 Correct 162 ms 21224 KB Output is correct
37 Correct 157 ms 18676 KB Output is correct
38 Correct 160 ms 17612 KB Output is correct
39 Correct 161 ms 17400 KB Output is correct
40 Correct 172 ms 15224 KB Output is correct
41 Correct 202 ms 14584 KB Output is correct
42 Correct 186 ms 14684 KB Output is correct
43 Correct 165 ms 20416 KB Output is correct
44 Incorrect 3 ms 376 KB 3rd lines differ - on the 1st token, expected: '3304', found: '182'
45 Halted 0 ms 0 KB -