답안 #485750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485750 2021-11-09T08:14:29 Z 5enpa1 Safety (NOI18_safety) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define int __int128
#define vec vector 
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define sq(x) (x)*(x)
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef pair<int,int> PII;
int f(int k, int b, int x){
	return k*x+b;
}
int k, x, b, y, sum;
long long n, h, ans;
signed main(){
	#ifdef LOCAL
		ifstream cin("input.txt");
		ofstream cout("output.txt");
	#endif
	fast_io;
	cin >> n >> h;
	vec < long long > q(n);
	vec < int > w;
	for(auto &i: q) cin >> i, sum += i;
	multiset < int > one;
	multiset < int > two;
	int left = 0;
	int right = 0;
	for(int i = 0; i < n; ++i){
		one.insert(q[i]-left);
		one.insert(q[i]-left);
		while(sz(one) > sz(two)){
			auto it = one.end();
			it--;
			int adder = *it;
			adder -= right;
			adder += left;
			two.insert(adder);
			one.erase(one.find(*it));
		}
		auto it = one.end();
		it--;
		while((*it)+left > (*two.begin())+right){
			two.insert(*it+left-right);
			one.erase(it);
			one.insert(*two.begin()+right-left);
			two.erase(two.begin()); 
			it = one.end();
			it--;
		}		
		left -= h;
		right += h;
	}
	left += h;
	right -= h;
	vec < int > fin;
	for(auto &i: one) fin.pb(i+left);
	for(auto &i: two) fin.pb(i+right);
	b = -sum;
	for(int i = 0; i < n; ++i)
		b -= i*h;
	k = n;
	ans = 1e18;
	for(int i = sz(fin)-1; i >= 0; --i){
		x = fin[i];
 
      
         y = k*x+b;
			ans = min(ans, y);
		
		k--;
		b += x;
	}
	cout << ans;
	return 0;
}

Compilation message

safety.cpp:17:6: error: extended character   is not valid in an identifier
   17 | long long n, h, ans;
      |      ^
safety.cpp: In function 'int main()':
safety.cpp:24:9: error: 'n' was not declared in this scope
   24 |  cin >> n >> h;
      |         ^
safety.cpp:72:20: error: no matching function for call to 'min(long int&, __int128&)'
   72 |    ans = min(ans, y);
      |                    ^
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 safety.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
safety.cpp:72:20: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and '__int128')
   72 |    ans = min(ans, y);
      |                    ^
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 safety.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
safety.cpp:72:20: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and '__int128')
   72 |    ans = min(ans, y);
      |                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from safety.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
safety.cpp:72:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   72 |    ans = min(ans, y);
      |                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from safety.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
safety.cpp:72:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   72 |    ans = min(ans, y);
      |                    ^