Submission #753490

#TimeUsernameProblemLanguageResultExecution timeMemory
753490armandCatfish Farm (IOI22_fish)C++17
9 / 100
91 ms13908 KiB
#include "fish.h"
#include <algorithm>
using namespace std;

long long solve3(int n, int m, vector<int>& x, vector<int>& y, vector<int>& w)
{
	int* a = new int [100001];
	long long * b = new long long[100001];
	int i;
	for (i = 0; i < m; i++)
		a[x[i]] = w[i];

}

long long solve2(int n, int m, vector<int>& x, vector<int>& y, vector<int>& w)
{
	int i, j;
	long long suma = 0, sumb = 0, ans, ans2=0, tmp;
	vector< pair<int, int> > a, b;
	for (i = 0; i < m; i++)
		if (x[i] == 0) {
			suma += w[i];
			a.push_back(make_pair(y[i], w[i]));
		}
		else {
			sumb += w[i];
			b.push_back(make_pair(y[i], w[i]));
		}
	ans = suma > sumb ? suma : sumb;
	if (n > 2) {
		sort(a.begin(), a.end());
		sort(b.begin(), b.end());
		ans2 = sumb;
		i = 0; j = 0;
		tmp = ans2;
		for (j = 0; j < b.size(); j++) {
			while (i < a.size() && a[i].first < b[j].first) {
				tmp += a[i].second;
				i++;
			}
			if (tmp > ans2) ans2 = tmp;
			if(i<a.size() && a[i].first == b[j].first)
				tmp += a[i++].second;
			tmp -= b[j].second;
			if (tmp > ans2)
				ans2 = tmp;
		}
		return ans > ans2 ? ans : ans2;
	}
	return ans;
}

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
	std::vector<int> W)
{
	int i;
	bool flag2 = true, flag3=true;
	long long ans = 0;
	for (i = 0; i < M; i++) {
		if (X[i] > 1)
			flag2 = false;
		if (Y[i] > 0)
			flag3 = false;
	}
	if (flag2)
		return solve2(N, M, X, Y, W);
	if (flag3)
		return solve3(N, M, X, Y, W);
	for (i = 0; i < W.size(); i++)
		ans += W[i];
	return ans;
}

Compilation message (stderr)

fish.cpp: In function 'long long int solve3(int, int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
fish.cpp:8:14: warning: unused variable 'b' [-Wunused-variable]
    8 |  long long * b = new long long[100001];
      |              ^
fish.cpp:13:1: warning: no return statement in function returning non-void [-Wreturn-type]
   13 | }
      | ^
fish.cpp: In function 'long long int solve2(int, int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
fish.cpp:36:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for (j = 0; j < b.size(); j++) {
      |               ~~^~~~~~~~~~
fish.cpp:37:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |    while (i < a.size() && a[i].first < b[j].first) {
      |           ~~^~~~~~~~~~
fish.cpp:42:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |    if(i<a.size() && a[i].first == b[j].first)
      |       ~^~~~~~~~~
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:69:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |  for (i = 0; i < W.size(); i++)
      |              ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...