Submission #47190

# Submission time Handle Problem Language Result Execution time Memory
47190 2018-04-28T17:54:35 Z PowerOfNinjaGo Ancient Books (IOI17_books) C++17
50 / 100
234 ms 113680 KB
//Power Of Ninja Go
#include <bits/stdc++.h>
#ifdef atom
	#include "grader.cpp"
#else
	#include "books.h"
#endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector< ii > vii;
#define X first
#define Y second
#define pb push_back
int n;
const int maxn = 1e6+5;
vector<int> p;
int a[maxn], b[maxn];
ll dist[maxn];
bool vis[maxn];
int cnt = 0;
void dfs(int u)
{
	if(vis[u]) return;
	vis[u] = true;
	a[cnt] = min(u, a[cnt]);
	b[cnt] = max(u, b[cnt]);
	dist[cnt] += abs(p[u]-u);
	dfs(p[u]);
}
long long minimum_walk(std::vector<int> P, int s)
{
	p = P;
	n = P.size();
	for(int i = 0; i< n; i++) a[i] = 1e9;
	for(int i = 0; i< n; i++)
	{
		if(vis[i]) continue;
		dfs(i); cnt++;
	}
	int ed = 0;
	ll res = 0;
	for(int i = 0; i< cnt; i++)
	{
		if(a[i] == b[i]) continue;
		//cout << a[i] << " " << b[i] << endl;
		if(a[i]< ed)
		{
			if(b[i]< ed)
			{
				res += dist[i];
			}
			else
			{
				res += dist[i];
				ed = b[i];
			}
		}
		else
		{
			res += 2*(a[i]-ed)+dist[i];
			ed = b[i];
		}
	}
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 612 KB Output is correct
7 Correct 2 ms 612 KB Output is correct
8 Correct 2 ms 612 KB Output is correct
9 Correct 2 ms 612 KB Output is correct
10 Correct 2 ms 612 KB Output is correct
11 Correct 2 ms 612 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 2 ms 616 KB Output is correct
15 Correct 2 ms 616 KB Output is correct
16 Correct 2 ms 616 KB Output is correct
17 Correct 2 ms 616 KB Output is correct
18 Correct 2 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 612 KB Output is correct
7 Correct 2 ms 612 KB Output is correct
8 Correct 2 ms 612 KB Output is correct
9 Correct 2 ms 612 KB Output is correct
10 Correct 2 ms 612 KB Output is correct
11 Correct 2 ms 612 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 2 ms 616 KB Output is correct
15 Correct 2 ms 616 KB Output is correct
16 Correct 2 ms 616 KB Output is correct
17 Correct 2 ms 616 KB Output is correct
18 Correct 2 ms 616 KB Output is correct
19 Correct 2 ms 616 KB Output is correct
20 Correct 3 ms 616 KB Output is correct
21 Correct 3 ms 616 KB Output is correct
22 Correct 2 ms 616 KB Output is correct
23 Correct 2 ms 616 KB Output is correct
24 Correct 2 ms 616 KB Output is correct
25 Correct 3 ms 616 KB Output is correct
26 Correct 2 ms 616 KB Output is correct
27 Correct 2 ms 616 KB Output is correct
28 Correct 2 ms 692 KB Output is correct
29 Correct 2 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 612 KB Output is correct
7 Correct 2 ms 612 KB Output is correct
8 Correct 2 ms 612 KB Output is correct
9 Correct 2 ms 612 KB Output is correct
10 Correct 2 ms 612 KB Output is correct
11 Correct 2 ms 612 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 2 ms 616 KB Output is correct
15 Correct 2 ms 616 KB Output is correct
16 Correct 2 ms 616 KB Output is correct
17 Correct 2 ms 616 KB Output is correct
18 Correct 2 ms 616 KB Output is correct
19 Correct 2 ms 616 KB Output is correct
20 Correct 3 ms 616 KB Output is correct
21 Correct 3 ms 616 KB Output is correct
22 Correct 2 ms 616 KB Output is correct
23 Correct 2 ms 616 KB Output is correct
24 Correct 2 ms 616 KB Output is correct
25 Correct 3 ms 616 KB Output is correct
26 Correct 2 ms 616 KB Output is correct
27 Correct 2 ms 616 KB Output is correct
28 Correct 2 ms 692 KB Output is correct
29 Correct 2 ms 744 KB Output is correct
30 Correct 205 ms 17260 KB Output is correct
31 Correct 234 ms 24052 KB Output is correct
32 Correct 179 ms 42476 KB Output is correct
33 Correct 164 ms 45660 KB Output is correct
34 Correct 232 ms 52380 KB Output is correct
35 Correct 171 ms 57532 KB Output is correct
36 Correct 156 ms 60824 KB Output is correct
37 Correct 178 ms 64936 KB Output is correct
38 Correct 163 ms 71324 KB Output is correct
39 Correct 198 ms 78140 KB Output is correct
40 Correct 182 ms 84868 KB Output is correct
41 Correct 193 ms 91504 KB Output is correct
42 Correct 181 ms 98228 KB Output is correct
43 Correct 164 ms 113680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 113680 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 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 612 KB Output is correct
7 Correct 2 ms 612 KB Output is correct
8 Correct 2 ms 612 KB Output is correct
9 Correct 2 ms 612 KB Output is correct
10 Correct 2 ms 612 KB Output is correct
11 Correct 2 ms 612 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 2 ms 616 KB Output is correct
15 Correct 2 ms 616 KB Output is correct
16 Correct 2 ms 616 KB Output is correct
17 Correct 2 ms 616 KB Output is correct
18 Correct 2 ms 616 KB Output is correct
19 Correct 2 ms 616 KB Output is correct
20 Correct 3 ms 616 KB Output is correct
21 Correct 3 ms 616 KB Output is correct
22 Correct 2 ms 616 KB Output is correct
23 Correct 2 ms 616 KB Output is correct
24 Correct 2 ms 616 KB Output is correct
25 Correct 3 ms 616 KB Output is correct
26 Correct 2 ms 616 KB Output is correct
27 Correct 2 ms 616 KB Output is correct
28 Correct 2 ms 692 KB Output is correct
29 Correct 2 ms 744 KB Output is correct
30 Correct 205 ms 17260 KB Output is correct
31 Correct 234 ms 24052 KB Output is correct
32 Correct 179 ms 42476 KB Output is correct
33 Correct 164 ms 45660 KB Output is correct
34 Correct 232 ms 52380 KB Output is correct
35 Correct 171 ms 57532 KB Output is correct
36 Correct 156 ms 60824 KB Output is correct
37 Correct 178 ms 64936 KB Output is correct
38 Correct 163 ms 71324 KB Output is correct
39 Correct 198 ms 78140 KB Output is correct
40 Correct 182 ms 84868 KB Output is correct
41 Correct 193 ms 91504 KB Output is correct
42 Correct 181 ms 98228 KB Output is correct
43 Correct 164 ms 113680 KB Output is correct
44 Incorrect 2 ms 113680 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -