Submission #289255

# Submission time Handle Problem Language Result Execution time Memory
289255 2020-09-02T13:43:52 Z eohomegrownapps Ancient Books (IOI17_books) C++14
0 / 100
1 ms 384 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int ptr = 0;
vector<int> cycle;
vector<int> p;
int n;

ll total = 0;

void findcycle(int i){
	total += abs(i-p[i]);
	cycle[i] = ptr;
	if (cycle[p[i]]!=-1){return;}
	findcycle(p[i]);
}

ll minimum_walk(std::vector<int> px, int s) {
	p = px;
	n = p.size();
	cycle.resize(n,-1);
	int minind = 0;
	ll tot = 0;
	for (int i = 0; i<n; i++){
		if (cycle[i]!=-1){continue;}
		total = 0;
		findcycle(i);
		if (total!=0){
			minind=i;
		}
		tot += total;
		ptr++;
	}
	//cout<<tot<<' '<<minind<<'\n';
	return tot+2*minind;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 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: '4728'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -