Submission #289243

# Submission time Handle Problem Language Result Execution time Memory
289243 2020-09-02T13:39:47 Z wdjpng Ancient Books (IOI17_books) C++17
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#include "books.h"

#define rep(i,n) for(int i = 0; i < n; i++)
#define lint long long
using namespace std;
vector<int>P;
vector<bool>vis;
int dfs(int v)
{
	if(vis[v]) return 0;
	vis[v]=true;
	return abs(v - P[v]) + dfs(P[v]);
}

long long minimum_walk(std::vector<int> p, int s) {

	int n = p.size();

	while(p[0]==0||p[1]==0){
		s++;
	}
	vis.resize(n);
	P=p;
	int count=0;
	int numComp=0;
	rep(i, n)
	{
		if(vis[i]){continue;}
		numComp++;
		count+=dfs(i);
	}

	return count+2*(numComp-1);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Incorrect 0 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 1 ms 256 KB Output is correct
2 Incorrect 0 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 1 ms 256 KB Output is correct
2 Incorrect 0 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 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4186'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -