Submission #297154

# Submission time Handle Problem Language Result Execution time Memory
297154 2020-09-11T10:04:22 Z tmwilliamlin168 Fun Tour (APIO20_fun) C++14
Compilation error
0 ms 0 KB
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> createFunTour(int n, int q) {
	vector<int> s(n), d(n), ans;
	array<int, 2> c{n+1};
	for(int i=0; i<n; ++i) {
		s[i]=attractionsBehind(0, i);
		if(s[i]>n/2)
			c=min(array<int, 2>{s[i], i}, c);
	}
	vector<int> e;
	for(int i=0; i<n; ++i) {
		d[i]=hoursRequired(c[1], i);
		if(d[i]==1)
			e.push_back(i);
	}
	vector<vector<int>> d2(e.size()-1), f(3);
	for(int i=0; i<e.size()-1; ++i)
		for(int j=0; j<n; ++j)
			d2[i].push_back(hoursRequired(e[i], j));
	for(int i=0; i<n; ++i) {
		if(i==c[1])
			continue;
		int j=0;
		while(j<e.size()-1&&d2[j][i]>d[i])
			++j;
		f[j].push_back(i);
	}
	for(int i=0; i<e.size(); ++i) {
		sort(f[i].begin(), f[i].end(), [&](const int &i, const int &j) {
			return d[i]<d[j];
		});
	}
	int p[3]={0, 1, 2};
	int l=-1;
	while(1) {
		sort(p, p+3, [&](const int &i, const int &j) {
			return f[i].size()>f[j].size();
		});
		if(f[p[0]].size()<f[p[1]].size()+f[p[2]].size()) {
			sort(p, p+3, [&](const int &i, const int &j) {
				return d[f[i].back()]>d[f[j].back();
			});
			int i=0;
			if(p[i]==l)
				++i;
			ans.push_back(f[p[i]].back());
			f[p[i]].pop_back();
			l=p[i];
		} else
			break;
	}
	f[p[1]].insert(f[p[1]].end(), f[p[2]].begin(), f[p[2]].end());
	sort(f[p[1]].begin(), f[p[1]].end(), [&](const int &i, const int &j) {
		return d[i]<d[j];
	});
	l=l==p[0];
	while(f[p[l]].size()) {
		ans.push_back(f[p[l]].back());
		f[p[l]].pop_back();
		l^=1;
	}
	ans.push_back(c[1]);
	// for(int a : ans)
		// cout << a << endl;
	return ans;
}

Compilation message

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:20:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i=0; i<e.size()-1; ++i)
      |               ~^~~~~~~~~~~
fun.cpp:27:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   while(j<e.size()-1&&d2[j][i]>d[i])
      |         ~^~~~~~~~~~~
fun.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i=0; i<e.size(); ++i) {
      |               ~^~~~~~~~~
fun.cpp: In lambda function:
fun.cpp:44:40: error: expected ']' before ';' token
   44 |     return d[f[i].back()]>d[f[j].back();
      |                                        ^
      |                                        ]