답안 #150202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150202 2019-09-01T07:53:30 Z usa1+samsung2(#3703, adman, nona1314, wowoto9772) 십자가 놓기 (FXCUP4_cross) C++17
0 / 100
6 ms 384 KB
#include "cross.h"
#include <algorithm>

long long SelectCross(int K, std::vector<int> I, std::vector<int> O) {
	std::vector<std::pair<int, int>> v1(I.size());
	std::vector<std::pair<int, int>> 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();
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 6 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 6 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 6 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -