답안 #47187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47187 2018-04-28T17:43:44 Z PowerOfNinjaGo 고대 책들 (IOI17_books) C++17
0 / 100
2 ms 460 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];
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]);
	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 += 2*(b[i]-a[i]);
			}
			else
			{
				res += 2*(b[i]-ed);
				ed = b[i];
			}
		}
		else
		{
			res += 2*(b[i]-ed);
			ed = b[i];
		}
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Incorrect 2 ms 408 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Incorrect 2 ms 408 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Incorrect 2 ms 408 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 460 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2720'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Incorrect 2 ms 408 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -