답안 #631101

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631101 2022-08-17T17:07:03 Z oliversommer 메기 농장 (IOI22_fish) C++17
0 / 100
109 ms 24920 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;
		}
	}

	// 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_sum1[i] + pref_sum0[N] - pref_sum0[i] > pref_sum1[pivot] + pref_sum0[N] - pref_sum0[pivot]) {
			pivot = i;
		}
	}

	return pref_sum1[pivot] + pref_sum0[N] - pref_sum0[pivot];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 4432 KB Output is correct
2 Correct 41 ms 5292 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 2 ms 1748 KB Output is correct
5 Runtime error 109 ms 24920 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Runtime error 4 ms 3540 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Runtime error 4 ms 3540 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 4432 KB Output is correct
2 Correct 41 ms 5292 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 2 ms 1748 KB Output is correct
5 Runtime error 109 ms 24920 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -