답안 #43629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43629 2018-03-18T17:32:45 Z faustaadp 고대 책들 (IOI17_books) C++14
0 / 100
2 ms 532 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
#include "books.h"
ll n,i,nx[101010],has,tam,kan[101010];
ll b[101010],ma;
void dfs(ll aa)
{
	ma=max(ma,aa);
	b[aa]=1;
	if(!b[nx[aa]])
		dfs(nx[aa]);
	has+=abs(aa-nx[aa]);
}
void dfs2(ll aa)
{
	b[aa]=2;
	if(b[nx[aa]]!=2)
		dfs2(nx[aa]);
	kan[aa]=ma;
}
long long minimum_walk(std::vector<int> p, int s) {
	n=p.size();
	for(i=0;i<n;i++)
	{
		if(p[i]==i)
			b[i]=1;
		else
			nx[i]=p[i];
	}
	for(i=0;i<n;i++)
	{
		if(!b[i])
		{
			ma=0;
			dfs(i);
			dfs2(i);
		}
	}
	ll hv=0;
	for(i=0;i<n;i++)
	{
		if(i>hv)
			has+=2;
		hv=max(kan[i],hv);
	}
	return has;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 1 ms 424 KB Output is correct
4 Correct 1 ms 496 KB Output is correct
5 Incorrect 1 ms 532 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 1 ms 424 KB Output is correct
4 Correct 1 ms 496 KB Output is correct
5 Incorrect 1 ms 532 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 1 ms 424 KB Output is correct
4 Correct 1 ms 496 KB Output is correct
5 Incorrect 1 ms 532 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 532 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 1 ms 424 KB Output is correct
4 Correct 1 ms 496 KB Output is correct
5 Incorrect 1 ms 532 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -