Submission #40150

# Submission time Handle Problem Language Result Execution time Memory
40150 2018-01-28T14:00:31 Z alenam0161 Ancient Books (IOI17_books) C++14
0 / 100
1 ms 3000 KB
#include "books.h"
#include <iostream>
using namespace std;
const int N = 1e6 + 7;
bool used[N];
vector<int> cycl,a;
long long ans;
void dfs(int v) {
	used[v] = true;
	cycl.push_back(v);
	ans += abs(a[v] - v);
	if (used[a[v]])return;
	dfs(a[v]);
}
long long minimum_walk(std::vector<int> p, int s) {
	a = p;
	int n = p.size();
	vector<pair<long long,int>> ms;
	for (int i = 0; i < n; ++i) {
		if (used[i])continue;
		ans = 0;
		cycl.clear();
		dfs(i);
		ms.push_back({ ans,i });
	}
	while (ms.size() > 0 && ms.back().first == 0)ms.pop_back();
	long long an = 0;
	for (int i = 0; i < ms.size(); ++i) {
		an += ms[i].first;// cout << ms[i].first << " " << ms[i].second << endl;
	}
	an += ms.back().second * 2;
	return an;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ms.size(); ++i) {
                    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3000 KB Output is correct
2 Correct 1 ms 3000 KB Output is correct
3 Correct 0 ms 3000 KB Output is correct
4 Correct 0 ms 3000 KB Output is correct
5 Correct 0 ms 3000 KB Output is correct
6 Incorrect 0 ms 3000 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 3000 KB Output is correct
2 Correct 1 ms 3000 KB Output is correct
3 Correct 0 ms 3000 KB Output is correct
4 Correct 0 ms 3000 KB Output is correct
5 Correct 0 ms 3000 KB Output is correct
6 Incorrect 0 ms 3000 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 3000 KB Output is correct
2 Correct 1 ms 3000 KB Output is correct
3 Correct 0 ms 3000 KB Output is correct
4 Correct 0 ms 3000 KB Output is correct
5 Correct 0 ms 3000 KB Output is correct
6 Incorrect 0 ms 3000 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 0 ms 3000 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 3000 KB Output is correct
2 Correct 1 ms 3000 KB Output is correct
3 Correct 0 ms 3000 KB Output is correct
4 Correct 0 ms 3000 KB Output is correct
5 Correct 0 ms 3000 KB Output is correct
6 Incorrect 0 ms 3000 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -