답안 #1048195

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048195 2024-08-08T04:53:29 Z 박영우(#11091) Bikeparking (EGOI24_bikeparking) C++17
컴파일 오류
0 ms 0 KB
//#define LOCAL
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 2010101
#define MAXQ 101010
#define INF 1'000'000'100'000'000'000
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
#define TC 1
#ifdef LOCAL
#define DEBUG(a) cout<<a
#define TEST true
#else
#define DEBUG(...) 1234
#define TEST false
#endif
int X[MAX], Y[MAX];
int XX[MAX], YY[MAX];
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	cin >> N;
	int i;
	set<int> st;
	int sx, sy;
	sx = sy = 0;
	for (i = 0; i < N; i++) cin >> X[i], XX[i] = X[i], sx += X[i];
	for (i = 0; i < N; i++) cin >> Y[i], YY[i] = Y[i], sy += Y[i];
	int l, r;
	l = 0;
	r = 1e9 + 10;
	auto get = [&](int x) {
		int i;
		for (i = 0; i < N; i++) {
			X[i] = XX[i];
			Y[i] = YY[i];
		}
		int rem = x;
		for (i = 0; i < N; i++) {
			int m = min(rem, Y[i]);
			Y[i] -= m;
			rem -= m;
		}

		rem = x + sx - sy;
		for (i = N - 1; i >= 0; i--) {
			int m = min(rem, X[i]);
			X[i] -= m;
			rem -= m;
		}

		for (i = 0; i < N; i++) if (X[i]) st.insert(i);
		ll sum = 0;
		int chk = 0;
		for (i = N - 1; i >= 0; i--) {
			while (Y[i]) {
				auto it = st.upper_bound(i);
				if (it == st.begin()) return -INF;
				else {
					it--;
					int m = min(Y[i], X[*it]);
					Y[i] -= m;
					X[*it] -= m;
					if (*it != i) sum += m;
					if (!X[*it]) st.erase(it);
				}
			}
			if (chk) break;
		}
		return sum - x;
	};
	while (r - l > 20) {
		int m = l + r >> 1;
		ll r1 = get(m);
		ll r2 = get(m + 1);
		if (r1 <= -INF) {
			l = m;
			continue;
		}
		if (r1 == r2) {
			cout << r1 << ln;
			return 0;
		}
		if (r1 < r2) l = m;
		else r = m + 1;
	}
	ll ans = -INF;
	for (i = l; i <= r; i++) ans = max(ans, get(i));
	cout << ans;
}

Compilation message

Main.cpp: In lambda function:
Main.cpp:80:14: error: inconsistent types 'long int' and 'long long int' deduced for lambda return type
   80 |   return sum - x;
      |          ~~~~^~~
Main.cpp: In function 'int main()':
Main.cpp:83:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |   int m = l + r >> 1;
      |           ~~^~~
Main.cpp:98:48: error: no matching function for call to 'max(ll&, long int)'
   98 |  for (i = l; i <= r; i++) ans = max(ans, get(i));
      |                                                ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
Main.cpp:98:48: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   98 |  for (i = l; i <= r; i++) ans = max(ans, get(i));
      |                                                ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
Main.cpp:98:48: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   98 |  for (i = l; i <= r; i++) ans = max(ans, get(i));
      |                                                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
Main.cpp:98:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   98 |  for (i = l; i <= r; i++) ans = max(ans, get(i));
      |                                                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
Main.cpp:98:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   98 |  for (i = l; i <= r; i++) ans = max(ans, get(i));
      |                                                ^