답안 #477723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477723 2021-10-03T10:26:11 Z Zhora_004 쌀 창고 (IOI11_ricehub) C++17
컴파일 오류
0 ms 0 KB
#include "ricehub.h"
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>

int besthub(int R, int L, int X[], long long B)
{
	multiset<int> tmp;
	for (int i = 0; i < R; i++) tmp.insert(X[i]);
	int mx = 0;
	for (int i = 1; i <= L; i++)
	{
		int ans = 0;
		multiset<int> ms = tmp;
		long long b = B;
		while (b)
		{
			auto it1 = ms.lower_bound(i);
			int num1 = -1, num2 = -1;
			if (it1 != ms.end()) num1 = *it1;
			if (it1 != ms.begin()) it1--, num2 = *it1;
			if (num1 == -1 && num2 == -1) continue;
			if (num1 == -1)
			{
				if (i - num2 <= b) b -= i - num2, ans++, ms.erase(ms.find(num2));
				else break;
			}
			else if (num2 == -1)
			{
				if (num1 - i <= b) b -= num1 - i, ans++, ms.erase(ms.find(num1));
				else break;
			}
			else
			{
				if (min(num1 - i, i - num2) <= b)
				{
					if (num1 - i <= i - num2) b -= num1 - i, ans++, ms.erase(ms.find(num1));
					else b -= i - num2, ans++, ms.erase(ms.find(num2));
				}
				else break;
			}
		}
		mx = max(mx, ans);
	}
	return mx;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:29:2: error: 'multiset' was not declared in this scope
   29 |  multiset<int> tmp;
      |  ^~~~~~~~
ricehub.cpp:29:2: note: suggested alternatives:
In file included from /usr/include/c++/10/set:61,
                 from ricehub.cpp:6:
/usr/include/c++/10/bits/stl_set.h:70:11: note:   'std::multiset'
   70 |     class multiset;
      |           ^~~~~~~~
In file included from ricehub.cpp:6:
/usr/include/c++/10/set:80:13: note:   'std::pmr::multiset'
   80 |       using multiset = std::multiset<_Key, _Cmp, polymorphic_allocator<_Key>>;
      |             ^~~~~~~~
ricehub.cpp:29:11: error: expected primary-expression before 'int'
   29 |  multiset<int> tmp;
      |           ^~~
ricehub.cpp:30:30: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   30 |  for (int i = 0; i < R; i++) tmp.insert(X[i]);
      |                              ^~~
      |                              tm
ricehub.cpp:35:12: error: expected primary-expression before 'int'
   35 |   multiset<int> ms = tmp;
      |            ^~~
ricehub.cpp:39:15: error: 'ms' was not declared in this scope; did you mean 'mx'?
   39 |    auto it1 = ms.lower_bound(i);
      |               ^~
      |               mx
ricehub.cpp:56:9: error: 'min' was not declared in this scope; did you mean 'std::min'?
   56 |     if (min(num1 - i, i - num2) <= b)
      |         ^~~
      |         std::min
In file included from /usr/include/c++/10/algorithm:62,
                 from ricehub.cpp:4:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: 'std::min' declared here
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
ricehub.cpp:64:8: error: 'max' was not declared in this scope; did you mean 'std::max'?
   64 |   mx = max(mx, ans);
      |        ^~~
      |        std::max
In file included from /usr/include/c++/10/algorithm:62,
                 from ricehub.cpp:4:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: 'std::max' declared here
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~