Submission #485739

# Submission time Handle Problem Language Result Execution time Memory
485739 2021-11-09T07:45:08 Z 5enpa1 Safety (NOI18_safety) C++17
Compilation error
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 
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:15:17: warning: extra tokens at end of #ifdef directive
   15 |   #ifdef LOCAL  ifstream cin("input.txt");  ofstream cout("output.txt");
      |                 ^~~~~~~~
safety.cpp:17:2: error: extended character   is not valid in an identifier
   17 |   fast_io;
      |  ^
safety.cpp:18:2: error: extended character   is not valid in an identifier
   18 |   int n, h; cin >> n >> h;
      |  ^
safety.cpp:19:2: error: extended character   is not valid in an identifier
   19 |   vec < int > q(n); vec < int > w; for(auto &i: q) cin >> i, sum += i;
      |  ^
safety.cpp:20:2: error: extended character   is not valid in an identifier
   20 |   multiset < int > one;
      |  ^
safety.cpp:21:2: error: extended character   is not valid in an identifier
   21 |   multiset < int > two;
      |  ^
safety.cpp:22:2: error: extended character   is not valid in an identifier
   22 |   int left = 0;
      |  ^
safety.cpp:23:2: error: extended character   is not valid in an identifier
   23 |   int right = 0;
      |  ^
safety.cpp:24:2: error: extended character   is not valid in an identifier
   24 |   for(int i = 0; i < n; ++i){  one.insert(q[i]-left);  one.insert(q[i]-left);
      |  ^
safety.cpp:25:2: error: extended character   is not valid in an identifier
   25 |        while(sz(one) > sz(two)){
      |  ^
safety.cpp:25:5: error: extended character   is not valid in an identifier
   25 |        while(sz(one) > sz(two)){
      |    ^
safety.cpp:25:8: error: extended character   is not valid in an identifier
   25 |        while(sz(one) > sz(two)){
      |      ^
safety.cpp:26:2: error: extended character   is not valid in an identifier
   26 |              auto it = one.end();
      |  ^
safety.cpp:26:5: error: extended character   is not valid in an identifier
   26 |              auto it = one.end();
      |    ^
safety.cpp:26:8: error: extended character   is not valid in an identifier
   26 |              auto it = one.end();
      |      ^
safety.cpp:26:11: error: extended character   is not valid in an identifier
   26 |              auto it = one.end();
      |        ^
safety.cpp:26:14: error: extended character   is not valid in an identifier
   26 |              auto it = one.end();
      |          ^
safety.cpp:26:17: error: extended character   is not valid in an identifier
   26 |              auto it = one.end();
      |            ^
safety.cpp:27:2: error: extended character   is not valid in an identifier
   27 |                it--;
      |  ^
safety.cpp:27:5: error: extended character   is not valid in an identifier
   27 |                it--;
      |    ^
safety.cpp:27:8: error: extended character   is not valid in an identifier
   27 |                it--;
      |      ^
safety.cpp:28:2: error: extended character   is not valid in an identifier
   28 |                int adder = *it;
      |  ^
safety.cpp:28:5: error: extended character   is not valid in an identifier
   28 |                int adder = *it;
      |    ^
safety.cpp:28:8: error: extended character   is not valid in an identifier
   28 |                int adder = *it;
      |      ^
safety.cpp:28:11: error: extended character   is not valid in an identifier
   28 |                int adder = *it;
      |        ^
safety.cpp:28:14: error: extended character   is not valid in an identifier
   28 |                int adder = *it;
      |          ^
safety.cpp:28:17: error: extended character   is not valid in an identifier
   28 |                int adder = *it;
      |            ^
safety.cpp:28:20: error: extended character   is not valid in an identifier
   28 |                int adder = *it;
      |              ^
safety.cpp:29:2: error: extended character   is not valid in an identifier
   29 |                 adder -= right;   adder += left;   two.insert(adder);   one.erase(one.find(*it));
      |  ^
safety.cpp:29:5: error: extended character   is not valid in an identifier
   29 |                 adder -= right;   adder += left;   two.insert(adder);   one.erase(one.find(*it));
      |    ^
safety.cpp:29:8: error: extended character   is not valid in an identifier
   29 |                 adder -= right;   adder += left;   two.insert(adder);   one.erase(one.find(*it));
      |      ^
safety.cpp:29:11: error: extended character   is not valid in an identifier
   29 |                 adder -= right;   adder += left;   two.insert(adder);   one.erase(one.find(*it));
      |        ^
safety.cpp:29:14: error: extended character   is not valid in an identifier
   29 |                 adder -= right;   adder += left;   two.insert(adder);   one.erase(one.find(*it));
      |          ^
safety.cpp:29:17: error: extended character   is not valid in an identifier
   29 |                 adder -= right;   adder += left;   two.insert(adder);   one.erase(one.find(*it));
      |            ^
safety.cpp:29:20: error: extended character   is not valid in an identifier
   29 |                 adder -= right;   adder += left;   two.insert(adder);   one.erase(one.find(*it));
      |              ^
safety.cpp:29:23: error: extended character   is not valid in an identifier
   29 |                 adder -= right;   adder += left;   two.insert(adder);   one.erase(one.find(*it));
      |                ^
safety.cpp:30:2: error: extended character   is not valid in an identifier
   30 |        }
      |  ^
safety.cpp:30:5: error: extended character   is not valid in an identifier
   30 |        }
      |    ^
safety.cpp:30:8: error: extended character   is not valid in an identifier
   30 |        }
      |      ^
safety.cpp:31:2: error: extended character   is not valid in an identifier
   31 |        auto it = one.end();
      |  ^
safety.cpp:31:5: error: extended character   is not valid in an identifier
   31 |        auto it = one.end();
      |    ^
safety.cpp:31:8: error: extended character   is not valid in an identifier
   31 |        auto it = one.end();
      |      ^
safety.cpp:32:2: error: extended character   is not valid in an identifier
   32 |        it--;
      |  ^
safety.cpp:32:5: error: extended character   is not valid in an identifier
   32 |        it--;
      |    ^
safety.cpp:32:8: error: extended character   is not valid in an identifier
   32 |        it--;
      |      ^
safety.cpp:33:2: error: extended character   is not valid in an identifier
   33 |   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; }
      |  ^
safety.cpp:34:2: error: extended character   is not valid in an identifier
   34 |   left += h; right -= h;
      |  ^
safety.cpp:35:2: error: extended character   is not valid in an identifier
   35 |   vec < int > fin;
      |  ^
safety.cpp:36:2: error: extended character   is not valid in an identifier
   36 |   for(auto &i: one) fin.pb(i+left);
      |  ^
safety.cpp:37:2: error: extended character   is not valid in an identifier
   37 |   for(auto &i: two) fin.pb(i+right);
      |  ^
safety.cpp:38:2: error: extended character   is not valid in an identifier
   38 |   b = -sum;
      |  ^
safety.cpp:39:2: error: extended character   is not valid in an identifier
   39 |   for(int i = 0; i < n; ++i)
      |  ^
safety.cpp:40:2: error: extended character   is not valid in an identifier
   40 |     b -= i*h; k = n;
      |  ^
safety.cpp:40:5: error: extended character   is not valid in an identifier
   40 |     b -= i*h; k = n;
      |    ^
safety.cpp:41:2: error: extended character   is not valid in an identifier
   41 |    int ans = 1e18;
      |  ^
safety.cpp:42:2: error: extended character   is not valid in an identifier
   42 |    for(int i = sz(fin)-1; i >= 0; --i){  x = fin[i];
      |  ^
safety.cpp:43:2: error: extended character   is not valid in an identifier
   43 |     if(x < (int)(1e16/abs(k))){   y = k*x+b;   ans = min(ans, y);  }  k--;  b += x; } cout << ans; return 0;}
      |  ^
safety.cpp:43:5: error: extended character   is not valid in an identifier
   43 |     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:17:2: error: '\U000000a0fast_io' was not declared in this scope; did you mean 'fast_io'?
   17 |   fast_io;
      |  ^~~~~~~~
      |  fast_io
safety.cpp:18:2: error: '\U000000a0int' was not declared in this scope
   18 |   int n, h; cin >> n >> h;
      |  ^~~~
safety.cpp:18:21: error: 'n' was not declared in this scope
   18 |   int n, h; cin >> n >> h;
      |                    ^
safety.cpp:18:26: error: 'h' was not declared in this scope
   18 |   int n, h; cin >> n >> h;
      |                         ^
safety.cpp:19:2: error: '\U000000a0vec' was not declared in this scope; did you mean 'vec'?
   19 |   vec < int > q(n); vec < int > w; for(auto &i: q) cin >> i, sum += i;
      |  ^~~~
      |  vec
safety.cpp:2:13: error: expected primary-expression before 'long'
    2 | #define int long long
      |             ^~~~
safety.cpp:19:10: note: in expansion of macro 'int'
   19 |   vec < int > q(n); vec < int > w; for(auto &i: q) cin >> i, sum += i;
      |         ^~~
safety.cpp:19:50: error: 'q' was not declared in this scope
   19 |   vec < int > q(n); vec < int > w; for(auto &i: q) cin >> i, sum += i;
      |                                                 ^
safety.cpp:20:2: error: '\U000000a0multiset' was not declared in this scope
   20 |   multiset < int > one;
      |  ^~~~~~~~~
safety.cpp:2:13: error: expected primary-expression before 'long'
    2 | #define int long long
      |             ^~~~
safety.cpp:20:15: note: in expansion of macro 'int'
   20 |   multiset < int > one;
      |              ^~~
safety.cpp:2:13: error: expected primary-expression before 'long'
    2 | #define int long long
      |             ^~~~
safety.cpp:21:15: note: in expansion of macro 'int'
   21 |   multiset < int > two;
      |              ^~~
safety.cpp:22:7: error: expected ';' before 'left'
   22 |   int left = 0;
      |      ^~~~~
      |      ;
safety.cpp:23:7: error: expected ';' before 'right'
   23 |   int right = 0;
      |      ^~~~~~
      |      ;
safety.cpp:2:13: error: expected primary-expression before 'long'
    2 | #define int long long
      |             ^~~~
safety.cpp:24:8: note: in expansion of macro 'int'
   24 |   for(int i = 0; i < n; ++i){  one.insert(q[i]-left);  one.insert(q[i]-left);
      |       ^~~
safety.cpp:24:19: error: 'i' was not declared in this scope
   24 |   for(int i = 0; i < n; ++i){  one.insert(q[i]-left);  one.insert(q[i]-left);
      |                  ^
safety.cpp:34:2: error: '\U000000a0left' was not declared in this scope
   34 |   left += h; right -= h;
      |  ^~~~~
safety.cpp:2:13: error: expected primary-expression before 'long'
    2 | #define int long long
      |             ^~~~
safety.cpp:35:10: note: in expansion of macro 'int'
   35 |   vec < int > fin;
      |         ^~~
safety.cpp:36:8: error: expected primary-expression before 'auto'
   36 |   for(auto &i: one) fin.pb(i+left);
      |       ^~~~
safety.cpp:36:2: error: '\U000000a0for' was not declared in this scope
   36 |   for(auto &i: one) fin.pb(i+left);
      |  ^~~~
safety.cpp:37:8: error: expected primary-expression before 'auto'
   37 |   for(auto &i: two) fin.pb(i+right);
      |       ^~~~
safety.cpp:38:2: error: '\U000000a0b' was not declared in this scope
   38 |   b = -sum;
      |  ^~
safety.cpp:2:13: error: expected primary-expression before 'long'
    2 | #define int long long
      |             ^~~~
safety.cpp:39:8: note: in expansion of macro 'int'
   39 |   for(int i = 0; i < n; ++i)
      |       ^~~
safety.cpp:41:2: error: '\U000000a0' was not declared in this scope
   41 |    int ans = 1e18;
      |  ^
safety.cpp:42:4: error: expected ';' before 'for'
   42 |    for(int i = sz(fin)-1; i >= 0; --i){  x = fin[i];
      |   ^~~~
      |   ;
safety.cpp:43:97: error: 'ans' was not declared in this scope; did you mean 'abs'?
   43 |     if(x < (int)(1e16/abs(k))){   y = k*x+b;   ans = min(ans, y);  }  k--;  b += x; } cout << ans; return 0;}
      |                                                                                               ^~~
      |                                                                                               abs