Submission #297126

# Submission time Handle Problem Language Result Execution time Memory
297126 2020-09-11T09:27:28 Z tmwilliamlin168 Fun Tour (APIO20_fun) C++14
0 / 100
1 ms 512 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(e.size());
	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].size()];
			});
			int i=0;
			if(p[i]==l)
				++i;
			ans.push_back(f[p[i]].back());
			f[p[i]].pop_back();
		} else
			break;
	}
	f[p[1]].insert(f[p[1]].end(), f[p[2]].begin(), f[p[2]].end());
	l=!l;
	while(f[p[l]].size()) {
		ans.push_back(f[p[l]].back());
		f[p[l]].pop_back();
		l^=1;
	}
	// vector<int> g;
	// for(int i=0; i<e.size(); ++i)
	// 	g.insert(g.end(), f[i].begin(), f[i].end());
	// sort(g.begin(), g.begin()+n/2, [&](const int &i, const int &j) {
	// 	return d[i]>d[j];
	// });
	// sort(g.begin()+n/2, g.end(), [&](const int &i, const int &j) {
	// 	return d[i]>d[j];
	// });
	// for(int i=0; i<n/2; ++i) {
	// 	ans.push_back(g[i]);
	// 	if(i+n/2<g.size())
	// 		ans.push_back(g[i+n/2]);
	// }
	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) {
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Tour is not fun
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Tour is not fun
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Tour is not fun