답안 #485741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485741 2021-11-09T07:54:06 Z 5enpa1 Safety (NOI18_safety) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define int long long 
#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 main(){	#ifdef LOCAL		ifstream cin("input.txt");		ofstream cout("output.txt");	#endif	fast_io;	int n, h;	cin >> n >> h;	vec < int > 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;	int ans = 1e18;	for(int i = sz(fin)-1; i >= 0; --i){		x = fin[i];		if(x < (int)(1e16/abs(k))){			y = k*x+b;			ans = min(ans, y);		}		k--;		b += x;	}	cout << ans;	return 0;}

Compilation message

safety.cpp:11:124: error: stray '#' in program
   11 | 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 main(){ #ifdef LOCAL  ifstream cin("input.txt");  ofstream cout("output.txt"); #endif fast_io; int n, h; cin >> n >> h; vec < int > 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; int ans = 1e18; for(int i = sz(fin)-1; i >= 0; --i){  x = fin[i];  if(x < (int)(1e16/abs(k))){   y = k*x+b;   ans = min(ans, y);  }  k--;  b += x; } cout << ans; return 0;}
      |                                                                                                                            ^
safety.cpp:11:195: error: stray '#' in program
   11 | 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 main(){ #ifdef LOCAL  ifstream cin("input.txt");  ofstream cout("output.txt"); #endif fast_io; int n, h; cin >> n >> h; vec < int > 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; int ans = 1e18; for(int i = sz(fin)-1; i >= 0; --i){  x = fin[i];  if(x < (int)(1e16/abs(k))){   y = k*x+b;   ans = min(ans, y);  }  k--;  b += x; } cout << ans; return 0;}
      |                                                                                                                                                                                                   ^
safety.cpp: In function 'int main()':
safety.cpp:11:125: error: 'ifdef' was not declared in this scope
   11 | 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 main(){ #ifdef LOCAL  ifstream cin("input.txt");  ofstream cout("output.txt"); #endif fast_io; int n, h; cin >> n >> h; vec < int > 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; int ans = 1e18; for(int i = sz(fin)-1; i >= 0; --i){  x = fin[i];  if(x < (int)(1e16/abs(k))){   y = k*x+b;   ans = min(ans, y);  }  k--;  b += x; } cout << ans; return 0;}
      |                                                                                                                             ^~~~~
safety.cpp:11:196: error: 'endif' was not declared in this scope
   11 | 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 main(){ #ifdef LOCAL  ifstream cin("input.txt");  ofstream cout("output.txt"); #endif fast_io; int n, h; cin >> n >> h; vec < int > 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; int ans = 1e18; for(int i = sz(fin)-1; i >= 0; --i){  x = fin[i];  if(x < (int)(1e16/abs(k))){   y = k*x+b;   ans = min(ans, y);  }  k--;  b += x; } cout << ans; return 0;}
      |                                                                                                                                                                                                    ^~~~~