Submission #73426

# Submission time Handle Problem Language Result Execution time Memory
73426 2018-08-28T08:56:39 Z Navick Ancient Books (IOI17_books) C++17
50 / 100
354 ms 29600 KB
#include <bits/stdc++.h>
#include "books.h"

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;

const int maxN = 1e6 + 10;

bool mark[maxN];
vector <pii> que;

long long minimum_walk(std::vector<int> p, int s) {
	int n = p.size(), m = 0;
	ll ans = 0;

	for (int i=0; i<n; i++)
	{
		if(mark[i]) continue ;
		int curr = i, mn = n, sz = 0, mx = 0;

		while(!mark[curr])
		{
			mn = min(mn, curr);
			mx = max(mx, curr);
			sz ++;
			mark[curr] = true;
			ans += abs(p[curr] - curr);
			curr = p[curr];
		}
		que.pb({mn, mx});
	}

	sort(que.begin(), que.end());
	int len = que.size();

	int maxR = 0, currL = 0;
		
	vector <pii> res;

	for (int i=0; i<len; i++)
	{
		if(maxR >= que[i].F) maxR = max(maxR, que[i].S);
		else
		{
			res.pb({currL, maxR});
			currL = maxR + 1;
			maxR = que[i].S;
		}
	}
	res.pb({currL, maxR});

	for (int i=0; i<(int)res.size(); i++)
		if(res[i].F != res[i].S) m = i;

	return ans + 2LL * m;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 3 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 524 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
8 Correct 3 ms 524 KB Output is correct
9 Correct 4 ms 524 KB Output is correct
10 Correct 3 ms 524 KB Output is correct
11 Correct 3 ms 524 KB Output is correct
12 Correct 3 ms 524 KB Output is correct
13 Correct 2 ms 524 KB Output is correct
14 Correct 3 ms 524 KB Output is correct
15 Correct 3 ms 524 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 3 ms 592 KB Output is correct
18 Correct 5 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 3 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 524 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
8 Correct 3 ms 524 KB Output is correct
9 Correct 4 ms 524 KB Output is correct
10 Correct 3 ms 524 KB Output is correct
11 Correct 3 ms 524 KB Output is correct
12 Correct 3 ms 524 KB Output is correct
13 Correct 2 ms 524 KB Output is correct
14 Correct 3 ms 524 KB Output is correct
15 Correct 3 ms 524 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 3 ms 592 KB Output is correct
18 Correct 5 ms 592 KB Output is correct
19 Correct 2 ms 620 KB Output is correct
20 Correct 3 ms 624 KB Output is correct
21 Correct 4 ms 624 KB Output is correct
22 Correct 3 ms 624 KB Output is correct
23 Correct 3 ms 624 KB Output is correct
24 Correct 4 ms 624 KB Output is correct
25 Correct 3 ms 704 KB Output is correct
26 Correct 3 ms 704 KB Output is correct
27 Correct 3 ms 704 KB Output is correct
28 Correct 2 ms 704 KB Output is correct
29 Correct 3 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 3 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 524 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
8 Correct 3 ms 524 KB Output is correct
9 Correct 4 ms 524 KB Output is correct
10 Correct 3 ms 524 KB Output is correct
11 Correct 3 ms 524 KB Output is correct
12 Correct 3 ms 524 KB Output is correct
13 Correct 2 ms 524 KB Output is correct
14 Correct 3 ms 524 KB Output is correct
15 Correct 3 ms 524 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 3 ms 592 KB Output is correct
18 Correct 5 ms 592 KB Output is correct
19 Correct 2 ms 620 KB Output is correct
20 Correct 3 ms 624 KB Output is correct
21 Correct 4 ms 624 KB Output is correct
22 Correct 3 ms 624 KB Output is correct
23 Correct 3 ms 624 KB Output is correct
24 Correct 4 ms 624 KB Output is correct
25 Correct 3 ms 704 KB Output is correct
26 Correct 3 ms 704 KB Output is correct
27 Correct 3 ms 704 KB Output is correct
28 Correct 2 ms 704 KB Output is correct
29 Correct 3 ms 704 KB Output is correct
30 Correct 329 ms 9408 KB Output is correct
31 Correct 354 ms 9408 KB Output is correct
32 Correct 252 ms 29600 KB Output is correct
33 Correct 231 ms 29600 KB Output is correct
34 Correct 241 ms 29600 KB Output is correct
35 Correct 228 ms 29600 KB Output is correct
36 Correct 192 ms 29600 KB Output is correct
37 Correct 194 ms 29600 KB Output is correct
38 Correct 261 ms 29600 KB Output is correct
39 Correct 185 ms 29600 KB Output is correct
40 Correct 254 ms 29600 KB Output is correct
41 Correct 309 ms 29600 KB Output is correct
42 Correct 220 ms 29600 KB Output is correct
43 Correct 234 ms 29600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 29600 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 3 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 524 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
8 Correct 3 ms 524 KB Output is correct
9 Correct 4 ms 524 KB Output is correct
10 Correct 3 ms 524 KB Output is correct
11 Correct 3 ms 524 KB Output is correct
12 Correct 3 ms 524 KB Output is correct
13 Correct 2 ms 524 KB Output is correct
14 Correct 3 ms 524 KB Output is correct
15 Correct 3 ms 524 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 3 ms 592 KB Output is correct
18 Correct 5 ms 592 KB Output is correct
19 Correct 2 ms 620 KB Output is correct
20 Correct 3 ms 624 KB Output is correct
21 Correct 4 ms 624 KB Output is correct
22 Correct 3 ms 624 KB Output is correct
23 Correct 3 ms 624 KB Output is correct
24 Correct 4 ms 624 KB Output is correct
25 Correct 3 ms 704 KB Output is correct
26 Correct 3 ms 704 KB Output is correct
27 Correct 3 ms 704 KB Output is correct
28 Correct 2 ms 704 KB Output is correct
29 Correct 3 ms 704 KB Output is correct
30 Correct 329 ms 9408 KB Output is correct
31 Correct 354 ms 9408 KB Output is correct
32 Correct 252 ms 29600 KB Output is correct
33 Correct 231 ms 29600 KB Output is correct
34 Correct 241 ms 29600 KB Output is correct
35 Correct 228 ms 29600 KB Output is correct
36 Correct 192 ms 29600 KB Output is correct
37 Correct 194 ms 29600 KB Output is correct
38 Correct 261 ms 29600 KB Output is correct
39 Correct 185 ms 29600 KB Output is correct
40 Correct 254 ms 29600 KB Output is correct
41 Correct 309 ms 29600 KB Output is correct
42 Correct 220 ms 29600 KB Output is correct
43 Correct 234 ms 29600 KB Output is correct
44 Incorrect 4 ms 29600 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -