Submission #418381

# Submission time Handle Problem Language Result Execution time Memory
418381 2021-06-05T10:28:00 Z ismoilov Rice Hub (IOI11_ricehub) C++14
Compilation error
0 ms 0 KB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
deque <int> fir, sec;
ll sum_fir, sum_sec;

ll check(){
	int ans;
	if(sec.size() == fir.size())
		ans = sec.front();
	else
		ans = fir.back();
	ll c = sum_sec - sum_fir;
	c += (ll) ans * fir.size();
	c -= (ll) ans * sec.size();
	return c;
}

int besthub(int r, int l, int X[], int b){
	int ans = 0;
	fp(i,0,r){
		sec.push_back(X[i]);
		sum_sec += X[i];
		if(fir.size() < sec.size()){
			sum_sec -= sec.front();
			sum_fir += sec.front();
			fir.push_back(sec.front());
			sec.pop_front();
		}
		
		while(b < check()){
			if(fir.empty()){
				sum_sec -= sec.back();
				sec.pop_back();
			}
			else{
				sum_fir -= fir.front();
				fir.pop_front();
			}
			
			if(fir.size() < sec.size()){
				sum_sec -= sec.front();
				sum_fir += sec.front();
				fir.push_back(sec.front());
				sec.pop_front();
			}
		}
		ans = max(ans, (int) fir.size() + (int) sec.size());
	}
	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, int)':
ricehub.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
ricehub.cpp:28:2: note: in expansion of macro 'fp'
   28 |  fp(i,0,r){
      |  ^~
/usr/bin/ld: /tmp/cczg4NWY.o: in function `main':
grader.cpp:(.text.startup+0xae): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status