Submission #631130

# Submission time Handle Problem Language Result Execution time Memory
631130 2022-08-17T17:43:15 Z oliversommer Catfish Farm (IOI22_fish) C++17
0 / 100
95 ms 24928 KB
#include "fish.h"

#include <assert.h>

#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

struct Fish {
	int x, y, weight;
	bool operator<(const Fish& a) const {
		return y < a.y;	 // x == a.x ? y < a.y : x < a.x;
	}
};

long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
	vector<Fish> all_fish(M);
	for (int i = 0; i < M; ++i) {
		all_fish[i] = {X[i], Y[i], W[i]};
	}
	// sort(all_fish.begin(), all_fish.end());

	vector<long long> pref_sum0(N + 1), pref_sum1(N + 1);
	int pivot = 0;
	for (int i = 0; i < M; ++i) {
		Fish& a = all_fish[i];
		assert(a.x == 0 || a.x == 1);
		if (a.x == 0) {
			pref_sum0[a.y + 1] = a.weight;
		} else {
			pref_sum1[a.y + 1] = a.weight;
		}
	}

	if(N == 2) {
		return max(pref_sum0[N], pref_sum1[N]);
	}

	// prefix sum
	for (int i = 1; i <= N; ++i) {
		pref_sum0[i] += pref_sum0[i - 1];
		pref_sum1[i] += pref_sum1[i - 1];
	}

	// find pivot
	for (int i = 0; i <= N; ++i) {
		if (pref_sum0[i] + pref_sum1[N] - pref_sum1[i] > pref_sum0[pivot] + pref_sum1[N] - pref_sum1[pivot]) {
			pivot = i;
		}
	}

	return pref_sum0[pivot] + pref_sum1[N] - pref_sum1[pivot];
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 4508 KB Output is correct
2 Correct 31 ms 5452 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 1 ms 1748 KB Output is correct
5 Runtime error 95 ms 24928 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 56 ms 7312 KB Output is correct
3 Correct 72 ms 8904 KB Output is correct
4 Correct 26 ms 4444 KB Output is correct
5 Correct 32 ms 5288 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '5050', found: '3030'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Runtime error 2 ms 3540 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Runtime error 2 ms 3540 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 4508 KB Output is correct
2 Correct 31 ms 5452 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 1 ms 1748 KB Output is correct
5 Runtime error 95 ms 24928 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -