Submission #340982

# Submission time Handle Problem Language Result Execution time Memory
340982 2020-12-28T20:20:37 Z pggp Ancient Books (IOI17_books) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>

using namespace std;

bool used[1000000];
vector < int > P;
int N;
int cur_cycle;
int cycle[1000000];
vector < vector < int > > cycs;
vector < int > l_cyc, r_cyc;

void dfs(int vertex){
	cycle[vertex] = cur_cycle;
	cycs[cur_cycle].push_back(vertex);
	used[vertex] = true;
	if(!used[P[vertex]]){
		dfs(P[vertex]);
	}
}

long long minimum_walk(vector < int > p, int s){
	N = p.size();
	P = p;
	cur_cycle = 0;
	for (int i = 0; i < N; ++i)
	{
		if(!used[i]){
			vector < int > v;
			cycs.push_back(v);
			dfs(i);
			cur_cycle++;
		}
	}

	vector < pair < int, int > > f;

	for (int i = 0; i < cycs.size(); ++i)
	{
		int l_cyc = 1000000;
		int r_cyc = 0;
		for(int v : cycs[i]){
			l_cyc = min(l_cyc, v);
			r_cyc = max(r_cyc, v);
		}
		f.push_back(make_pair(l_cyc, r_cyc));
	}


	sort(f.begin(), f.end());

	long long ans = 0;

	for (int i = 0; i < f.size(); ++i)
	{
		//cout << f[i].first << " " << f[i].second << endl;
		ans += 2 * (f[i].second - f[i].first);
	}
	ans += 2*(f[f.size() - 1].first - f[0].first);
	return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for (int i = 0; i < cycs.size(); ++i)
      |                  ~~^~~~~~~~~~~~~
books.cpp:54:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |  for (int i = 0; i < f.size(); ++i)
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 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 364 KB Output is correct
2 Incorrect 1 ms 364 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 364 KB Output is correct
2 Incorrect 1 ms 364 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 364 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4712'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -