Submission #114016

# Submission time Handle Problem Language Result Execution time Memory
114016 2019-05-29T14:52:15 Z faustaadp Ancient Books (IOI17_books) C++17
0 / 100
2 ms 384 KB
#include "books.h"
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,i,sud[1010101],p[1010101];
ll car(ll aa)
{
	if(p[aa]==aa)
		return aa;
	else
		return p[aa]=car(p[aa]);
}
void gab(ll aa,ll bb)
{
	p[car(aa)]=car(bb);
}
long long minimum_walk(std::vector<int> x, int s) 
{
	n=x.size();
	ll jaw=0;
	for(i=0;i<n;i++)p[i]=i;
	for(i=0;i<n;i++)jaw+=abs(i-x[i]);
	for(i=0;i<n;i++)
		gab(i,x[i]);
	ll tam=0;
	for(i=0;i<n;i++)
	{
		if(sud[car(i)])continue;
		else tam=i*2;
		sud[car(i)]=1;
	}
	return jaw+tam;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4736'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -