답안 #151991

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151991 2019-09-05T19:44:59 Z minty99 King of Chairs (FXCUP4_chairs) C++17
100 / 100
585 ms 10832 KB
#include "king.h"
#include <algorithm>

long long SendInfo(std::vector<int> W, std::vector<int> C) {
	sort(W.begin(), W.end());
	sort(C.begin(), C.end());
	int last = 0;
	long long ans = 0;
	for(int w : W)
	{
		while(last < C.size() && w > C[last]) last++;
		if(last < C.size() && w <= C[last]) ans = w;
	}
	// return ans;
	return 0;
}
#include "vassal.h"
#include <algorithm>
#include <utility>
typedef std::pair<int, int> pii;

long long BB;
std::vector<pii> CC;
int isSeated[1100000];
void Init(long long B, std::vector<int> C){
	int N = C.size();
	BB = B;
	for(int i = 0; i < N; i++)
		CC.emplace_back(C[i], i);
	sort(CC.begin(), CC.end());
	for(int i = 0; i < 1100000; i++) isSeated[i] = -1;
}

int Maid(int W) {
	// if(W > BB) return -1;
	auto it = lower_bound(CC.begin(), CC.end(), pii(W, -1));
	if(it == CC.end()) return -1;
	int orig_pos = it->second, pos = it->second;
	while(isSeated[pos] >= 0) pos = isSeated[pos]+1;
	if(pos >= CC.size()) return -1;
	isSeated[orig_pos] = pos;
	isSeated[pos] = pos;
	// printf("W = %d orig = %d pos = %d\n", W, orig_pos, pos);
	return pos;
}

Compilation message

king.cpp: In function 'long long int SendInfo(std::vector<int>, std::vector<int>)':
king.cpp:11:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(last < C.size() && w > C[last]) last++;
         ~~~~~^~~~~~~~~~
king.cpp:12:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(last < C.size() && w <= C[last]) ans = w;
      ~~~~~^~~~~~~~~~
king.cpp:8:12: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
  long long ans = 0;
            ^~~

vassal.cpp: In function 'int Maid(int)':
vassal.cpp:24:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(pos >= CC.size()) return -1;
     ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4984 KB Correct
2 Correct 8 ms 5116 KB Correct
3 Correct 8 ms 5112 KB Correct
4 Correct 8 ms 5112 KB Correct
5 Correct 7 ms 4852 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 8108 KB Correct
2 Correct 121 ms 10212 KB Correct
3 Correct 565 ms 10672 KB Correct
4 Correct 109 ms 10516 KB Correct
5 Correct 124 ms 10524 KB Correct
6 Correct 128 ms 10632 KB Correct
7 Correct 585 ms 10552 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 8144 KB Correct
2 Correct 107 ms 10484 KB Correct
3 Correct 182 ms 10548 KB Correct
4 Correct 115 ms 10696 KB Correct
5 Correct 117 ms 10696 KB Correct
6 Correct 114 ms 10832 KB Correct
7 Correct 188 ms 10740 KB Correct
8 Correct 93 ms 10656 KB Correct