답안 #47189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47189 2018-04-28T17:54:03 Z PowerOfNinjaGo 고대 책들 (IOI17_books) C++17
22 / 100
219 ms 24136 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];
int 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 684 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 696 KB Output is correct
14 Correct 2 ms 828 KB Output is correct
15 Correct 2 ms 828 KB Output is correct
16 Correct 2 ms 828 KB Output is correct
17 Correct 2 ms 828 KB Output is correct
18 Correct 2 ms 828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 684 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 696 KB Output is correct
14 Correct 2 ms 828 KB Output is correct
15 Correct 2 ms 828 KB Output is correct
16 Correct 2 ms 828 KB Output is correct
17 Correct 2 ms 828 KB Output is correct
18 Correct 2 ms 828 KB Output is correct
19 Correct 2 ms 828 KB Output is correct
20 Correct 2 ms 828 KB Output is correct
21 Correct 2 ms 828 KB Output is correct
22 Correct 2 ms 828 KB Output is correct
23 Correct 2 ms 828 KB Output is correct
24 Correct 2 ms 828 KB Output is correct
25 Correct 2 ms 828 KB Output is correct
26 Correct 2 ms 828 KB Output is correct
27 Correct 2 ms 828 KB Output is correct
28 Correct 2 ms 832 KB Output is correct
29 Correct 2 ms 836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 684 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 696 KB Output is correct
14 Correct 2 ms 828 KB Output is correct
15 Correct 2 ms 828 KB Output is correct
16 Correct 2 ms 828 KB Output is correct
17 Correct 2 ms 828 KB Output is correct
18 Correct 2 ms 828 KB Output is correct
19 Correct 2 ms 828 KB Output is correct
20 Correct 2 ms 828 KB Output is correct
21 Correct 2 ms 828 KB Output is correct
22 Correct 2 ms 828 KB Output is correct
23 Correct 2 ms 828 KB Output is correct
24 Correct 2 ms 828 KB Output is correct
25 Correct 2 ms 828 KB Output is correct
26 Correct 2 ms 828 KB Output is correct
27 Correct 2 ms 828 KB Output is correct
28 Correct 2 ms 832 KB Output is correct
29 Correct 2 ms 836 KB Output is correct
30 Incorrect 219 ms 24136 KB 3rd lines differ - on the 1st token, expected: '333035179244', found: '2322697452'
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 24136 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 684 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 696 KB Output is correct
14 Correct 2 ms 828 KB Output is correct
15 Correct 2 ms 828 KB Output is correct
16 Correct 2 ms 828 KB Output is correct
17 Correct 2 ms 828 KB Output is correct
18 Correct 2 ms 828 KB Output is correct
19 Correct 2 ms 828 KB Output is correct
20 Correct 2 ms 828 KB Output is correct
21 Correct 2 ms 828 KB Output is correct
22 Correct 2 ms 828 KB Output is correct
23 Correct 2 ms 828 KB Output is correct
24 Correct 2 ms 828 KB Output is correct
25 Correct 2 ms 828 KB Output is correct
26 Correct 2 ms 828 KB Output is correct
27 Correct 2 ms 828 KB Output is correct
28 Correct 2 ms 832 KB Output is correct
29 Correct 2 ms 836 KB Output is correct
30 Incorrect 219 ms 24136 KB 3rd lines differ - on the 1st token, expected: '333035179244', found: '2322697452'
31 Halted 0 ms 0 KB -