답안 #38762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38762 2018-01-06T12:42:47 Z Waschbar Gap (APIO16_gap) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;

const long long INF = 1e18;

long long findGap(int T, int N) {

	multiset < pair< long long,pair<long long,long long> > > st;
	long long mn, mx;
	MinMax(0ll,INF,&mn,&mx);
	st.insert({-(mx-mn),{mn,mx}});
	long long ans = 0;

    if(n == 2){
        return mx - mn;
    }

    long long mnds = (mx-mn)/(n-1);

	int kk = 0;
	if(mn != -1) kk++;
	if(mn != mx) kk++;

	while(!st.empty()) {
		long long L, R;
		if(abs(st.begin()->first) <= ans)
			return ans;

		L = st.begin()->second.first;
		R = st.begin()->second.second;
		st.erase(st.begin());
		long long a1, a2, a3, a4;
		a1 = a1 = a3 = a4 = -1;
          if(kk != N && L != (L+R)/2 && ((L+R)/2-L) >= mnds) {
			MinMax(L,(L+R)/2,&a1,&a2);
            if(a1 != -1) kk++;
            if(a2 != a1) kk++;
          }
          if(kk != N && R != (L+R)/2+1 && (R-(L+R)/2+1) >= mnds) {
			MinMax((L+R)/2+1,R,&a3,&a4);
			if(a3 != -1) kk++;
            if(a4 != a1) kk++;
          }

			if(a1 == a2 && a1 != -1)
				ans = max(ans,a2-L);
			if(a2-a1 == 1 && a1 != -1)
				ans = max(ans,1ll);
			if(a1-L == 1 && a1 != -1)
				ans = max(ans,1ll);

			if(a3 == a4 && a4 != -1)
				ans = max(ans,R-a3);
			if(a4-a3 == 1 && a3 != -1)
				ans = max(ans,1ll);
			if(R-a4 == 1 && a4 != -1)
				ans = max(ans,1ll);

			if(a2 != -1 && a3 != -1)
				ans = max(ans,a3-a2);
			if(a3 == -1 && a1 == -1)
				ans = max(ans,R-L);
			if(a1 == -1 && a3 != -1)
				ans = max(ans,a3-L);
			if(a3 == -1 && a2 != -1)
				ans = max(ans,R-a2);

			if(a1 != -1 && a1-L > 1)
				st.insert({L-a1,{L,a1}});
			if(a1 != -1 && a2-a1 > 1)
				st.insert({a1-a2,{a1,a2}});
			if(a1 != -1 &&  a3 != -1 && a3-a2 > 1)
				st.insert({a2-a3,{a2,a3}});
			if(a3 != -1 && a4-a3 > 1)
				st.insert({a3-a4,{a3,a4}});
			if(a3 != -1 && R-a4 > 1)
				st.insert({a4-R,{a4,R}});
	}

	return ans;

	return 0;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:15:8: error: 'n' was not declared in this scope
     if(n == 2){
        ^
gap.cpp:19:31: error: 'n' was not declared in this scope
     long long mnds = (mx-mn)/(n-1);
                               ^
gap.cpp:34:25: warning: operation on 'a1' may be undefined [-Wsequence-point]
   a1 = a1 = a3 = a4 = -1;
                         ^