Submission #150212

# Submission time Handle Problem Language Result Execution time Memory
150212 2019-09-01T07:54:34 Z usa1+samsung2(#3703, adman, nona1314, wowoto9772) Crosses on the Grid (FXCUP4_cross) C++17
0 / 100
6 ms 512 KB
#include "cross.h"
#include <algorithm>

long long SelectCross(int K, std::vector<int> I, std::vector<int> O) {
	std::vector<std::pair<long long, long long>> v1(I.size());
	std::vector<std::pair<long long, long long>> v2(I.size());
	int N = I.size();

	for (int i = 0; i < I.size(); i++) {
		v1[i].first = I[i];
		v1[i].second = O[i];
	}

	for (int i = 0; i < I.size(); i++) {
		v2[i].first = O[i];
		v2[i].second = I[i];
	}

	std::sort(v1.rbegin(), v1.rend());
	std::sort(v2.rbegin(), v2.rend());

	long long l1 = v1[0].first, l2 = v1[0].second;

	for (int i = 1; i < K; i++) {
		if (l1 > v1[i].first) l1 = v1[i].first;
		if (l2 > v1[i].second) l2 = v1[i].second;
	}


	long long ans = l2 * l2 - (l2 - l1)*(l2 - l1);

	l1 = v1[0].first, l2 = v1[0].second;

	for (int i = 1; i < K; i++) {
		if (l1 > v1[i].first) l1 = v1[i].first;
		if (l2 > v1[i].second) l2 = v1[i].second;
	}

	if (ans < l1 * l1 - (l1 - l2)*(l1 - l2)) 
		ans = l1 * l1 - (l1 - l2)*(l1 - l2);

	return ans;
}

Compilation message

cross.cpp: In function 'long long int SelectCross(int, std::vector<int>, std::vector<int>)':
cross.cpp:9:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < I.size(); i++) {
                  ~~^~~~~~~~~~
cross.cpp:14:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < I.size(); i++) {
                  ~~^~~~~~~~~~
cross.cpp:7:6: warning: unused variable 'N' [-Wunused-variable]
  int N = I.size();
      ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Incorrect 6 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Incorrect 6 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Incorrect 6 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -