Submission #149174

# Submission time Handle Problem Language Result Execution time Memory
149174 2019-09-01T05:53:18 Z distutpia(#3780, cblimmm, wooks1998) Crosses on the Grid (FXCUP4_cross) C++17
100 / 100
131 ms 6876 KB
#include "cross.h"
#include <queue>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

struct cross{
	int d0;
	int d1;
};

struct cross C[200000];


bool comp0(struct cross a, struct cross b){
	return a.d0>b.d0;
}

bool comp1(struct cross a, struct cross b){
	return a.d1>b.d1;
}


long long SelectCross(int K, std::vector<int> I, std::vector<int> O) {
	vector<struct cross> C;
	priority_queue<int, vector<int>, greater<int> > PQ;
	struct cross temp;
	int N = I.size();
	for (int i=0; i<N; i++){
		temp.d0 = I[i];
		temp.d1 = O[i]; 
		C.push_back(temp);
	}
	sort(C.begin(), C.end(), comp0);
	int j=0;
	long long int max = 0;
	long long int dmin0 = 1000000000;
	long long int dmin1;
	for (int i=0; i<K; i++){
		PQ.push(C[j].d1);
		dmin0 = C[j].d0;
		//printf("!%d %d\n", C[j].d1, C[j].d0);
		j++;
	}
	long long int t;
	while(true){
		dmin1 = PQ.top();
		t = -dmin0*dmin0 + 2*dmin0*dmin1;
		//printf("!!%d\n",t);
		if (t>max){
			max = t;
		}
		if (j == N){
			break;
		}
		while(dmin1>=C[j].d1 && j!=N){
			j++;
		}
		if (j == N){
			break;
		}
		PQ.pop();
		PQ.push(C[j].d1);
		dmin0 = C[j].d0;
		j++;
	}
	return max;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 12 ms 768 KB Output is correct
6 Correct 116 ms 5736 KB Output is correct
7 Correct 117 ms 5736 KB Output is correct
8 Correct 115 ms 5740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 12 ms 768 KB Output is correct
6 Correct 116 ms 5736 KB Output is correct
7 Correct 117 ms 5736 KB Output is correct
8 Correct 115 ms 5740 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 12 ms 768 KB Output is correct
13 Correct 64 ms 3188 KB Output is correct
14 Correct 120 ms 5736 KB Output is correct
15 Correct 118 ms 5732 KB Output is correct
16 Correct 120 ms 5736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 12 ms 768 KB Output is correct
6 Correct 116 ms 5736 KB Output is correct
7 Correct 117 ms 5736 KB Output is correct
8 Correct 115 ms 5740 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 12 ms 768 KB Output is correct
13 Correct 64 ms 3188 KB Output is correct
14 Correct 120 ms 5736 KB Output is correct
15 Correct 118 ms 5732 KB Output is correct
16 Correct 120 ms 5736 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 14 ms 768 KB Output is correct
20 Correct 65 ms 3180 KB Output is correct
21 Correct 93 ms 5000 KB Output is correct
22 Correct 115 ms 5736 KB Output is correct
23 Correct 120 ms 5740 KB Output is correct
24 Correct 126 ms 5740 KB Output is correct
25 Correct 126 ms 6492 KB Output is correct
26 Correct 131 ms 6876 KB Output is correct