답안 #485747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485747 2021-11-09T08:12:01 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;
signed n, h, ans;
signed main(){
	#ifdef LOCAL
		ifstream cin("input.txt");
		ofstream cout("output.txt");
	#endif
	fast_io;
	cin >> n >> h;
	vec < signed > 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:25:8: error: extended character   is not valid in an identifier
   25 |  vec < signed > q(n);
      |        ^
safety.cpp: In function 'int main()':
safety.cpp:25:8: error: 'signed\U000000a0' was not declared in this scope; did you mean 'signed'?
   25 |  vec < signed > q(n);
      |        ^~~~~~~
      |        signed
safety.cpp:25:16: error: template argument 1 is invalid
   25 |  vec < signed > q(n);
      |               ^
safety.cpp:25:16: error: template argument 2 is invalid
safety.cpp:27:15: error: 'begin' was not declared in this scope
   27 |  for(auto &i: q) cin >> i, sum += i;
      |               ^
safety.cpp:27:15: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from safety.cpp:1:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from safety.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
safety.cpp:27:15: error: 'end' was not declared in this scope
   27 |  for(auto &i: q) cin >> i, sum += i;
      |               ^
safety.cpp:27:15: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from safety.cpp:1:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from safety.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
safety.cpp:33:15: error: invalid types 'int[__int128]' for array subscript
   33 |   one.insert(q[i]-left);
      |               ^
safety.cpp:34:15: error: invalid types 'int[__int128]' for array subscript
   34 |   one.insert(q[i]-left);
      |               ^
safety.cpp:66:8: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   66 |  ans = 1e18;
      |        ^~~~
safety.cpp:72:20: error: no matching function for call to 'min(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' ('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' ('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 '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 'int'
   72 |    ans = min(ans, y);
      |                    ^