답안 #149003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149003 2019-09-01T05:32:27 Z 갓띵건(#3694, gs18103, sjimed, gs18065) 십자가 놓기 (FXCUP4_cross) C++17
100 / 100
122 ms 6880 KB
#include "cross.h"
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false);cin.tie(0)
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define pre(a) cout<<fixed;cout.precision(a)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

priority_queue<int> pQ;
vector<pii> v;

long long SelectCross(int K, std::vector<int> I, std::vector<int> O) {
	int n = I.size();
	for(int i=0; i<n; i++) {
		v.eb(I[i], O[i]);
	}

	sort(all(v));
	ll ans = 0;

	for(int i=n-1; i >= 0; i--) {
		if(pQ.size() == K-1) {
			ll out;
			if(K > 1) out = min(v[i].se, -pQ.top());
			else out = v[i].se;
			ll in = v[i].fi;

			ans = max(ans, 2 * out * in - in * in);
		}

		if(pQ.size() < K-1) pQ.push(-v[i].se);
		else if(pQ.size() && -pQ.top() < v[i].se)  {
			pQ.pop();
			pQ.push(-v[i].se);
		}
	}

	return ans;
}

Compilation message

cross.cpp: In function 'long long int SelectCross(int, std::vector<int>, std::vector<int>)':
cross.cpp:32:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(pQ.size() == K-1) {
      ~~~~~~~~~~^~~~~~
cross.cpp:41:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(pQ.size() < K-1) pQ.push(-v[i].se);
      ~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 Correct 6 ms 256 KB Output is correct
5 Correct 12 ms 764 KB Output is correct
6 Correct 115 ms 5480 KB Output is correct
7 Correct 111 ms 5736 KB Output is correct
8 Correct 111 ms 5484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 Correct 6 ms 256 KB Output is correct
5 Correct 12 ms 764 KB Output is correct
6 Correct 115 ms 5480 KB Output is correct
7 Correct 111 ms 5736 KB Output is correct
8 Correct 111 ms 5484 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 128 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 12 ms 768 KB Output is correct
13 Correct 61 ms 3184 KB Output is correct
14 Correct 112 ms 5740 KB Output is correct
15 Correct 114 ms 5740 KB Output is correct
16 Correct 121 ms 5736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 Correct 6 ms 256 KB Output is correct
5 Correct 12 ms 764 KB Output is correct
6 Correct 115 ms 5480 KB Output is correct
7 Correct 111 ms 5736 KB Output is correct
8 Correct 111 ms 5484 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 128 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 12 ms 768 KB Output is correct
13 Correct 61 ms 3184 KB Output is correct
14 Correct 112 ms 5740 KB Output is correct
15 Correct 114 ms 5740 KB Output is correct
16 Correct 121 ms 5736 KB Output is correct
17 Correct 5 ms 128 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 13 ms 896 KB Output is correct
20 Correct 63 ms 3180 KB Output is correct
21 Correct 90 ms 5100 KB Output is correct
22 Correct 114 ms 5740 KB Output is correct
23 Correct 114 ms 5736 KB Output is correct
24 Correct 116 ms 5740 KB Output is correct
25 Correct 122 ms 6632 KB Output is correct
26 Correct 118 ms 6880 KB Output is correct