QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533184#8645. Growing Vegetables is Fun 5Nevll#0 3585ms11216kbC++142.6kb2024-08-25 18:12:342024-08-25 18:12:34

Judging History

This is the latest submission verdict.

  • [2024-08-25 18:12:34]
  • Judged
  • Verdict: 0
  • Time: 3585ms
  • Memory: 11216kb
  • [2024-08-25 18:12:34]
  • Submitted

answer

# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
# define pii pair<int, int>
using namespace std;

vector<int> A, B, C;
bool pos[4][300001];

int pref[2][300010], N;

int solve() {
	int lf = 0, rg = 1e9, ans = 0;
	while(lf <= rg) {
		int mid = (lf + rg) / 2;
	//	cout<<"mid ; "<<mid<<endl;
		for(int i=0;i<=N;i++) {
			pos[0][i] = pos[1][i] = pos[2][i] = pos[3][i] = 1;
			pref[0][i] = pref[1][i] = 0;
		}
		
		for(int i=0;i<N;i++) {
			if(i > 0 && pos[0][i - 1] == 0) pos[0][i] = 0;
			if(abs(A[i] - B[i]) > mid) pos[0][i] = 0;
		}
		for(int i=N;i<2*N;i++) {
			if(i > N && pos[1][i - N - 1] == 0) pos[1][i - N] = 0;
			if(abs(A[i] - C[2 * N - i - 1]) > mid) pos[1][i - N] = 0;
		}
		
	//	if(mid == 9) {
	//		for(int i=0;i<N;i++) cout<<"pos ; "<<pos[0][i]<<" "<<pos[1][i]<<endl;
	//	}
		for(int i=N-1;i>=0;i--) {
			int l = lower_bound(C.begin(), C.end(), A[i] - mid) - C.begin();
			int r = upper_bound(C.begin(), C.end(), A[i] + mid) - C.begin() - 1;
			
			l += (N - i - 1);
			r += (N - i - 1);
			
		//	if(mid == 9) cout<<"l, r : "<<l<<" "<<r<<endl;
			if(l > N) continue;
			r = min(r, N);
			
			pref[0][l]++;
			pref[0][r + 1]--;
		}
		
		for(int i=2*N-1;i>=0;i--) {
			int l = lower_bound(B.begin(), B.end(), A[i] - mid) - B.begin();
			int r = upper_bound(B.begin(), B.end(), A[i] + mid) - B.begin() - 1;
			
			l -= (2 * N - i - 1);
			r -= (2 * N - i - 1);
			if(r < 0) continue;
			l = max(l, 0);
			
			pref[1][l]++;
			pref[1][r + 1]--;
		}
		
		int x1=  0, x2 = 0;
		for(int i=0;i<N;i++) {
			x1 += pref[0][i];
			x2 += pref[1][i];
			if(x1 == i + 1) pos[2][i] = 1;
			if(x2 == i + 1) pos[3][i] = 1;
		}
		
		bool cek = 0;
		for(int i=0;i<N;i++) {
		//	cout<<"pos3 : "<<pos[2][i]<<" "<<pos[3][i]<<endl;
			if(pos[0][i] && pos[2][N - i - 1] && pos[1][i] && pos[3][N - i - 1]) cek = 1;
		}
		if(cek) {
			ans = mid;
			rg = mid - 1;
		} else lf = mid + 1;
	}
	return ans;
}

int main() {
	scanf("%d", &N);
	A.resize(2 * N);
	B.resize(N);
	C.resize(N);
	
	for(int i=0;i<2*N;i++) scanf("%d", &A[i]);
	for(int i=0;i<N;i++) scanf("%d", &B[i]);
	for(int i=0;i<N;i++) scanf("%d", &C[i]); 
	
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());
	
	int ans = solve();
	for(int i=0;i<N;i++) swap(B[i], C[i]);
	ans = min(ans, solve());
	
	int mx= 0 , mn = 0;
	for(int i=0;i<N;i++) {
		mx = max(mx, abs(A[i] - B[i]));
		mn = max(mn, abs(A[i] - C[i]));
	}
	for(int i=N;i<2*N;i++) {
		mx = max(mx, abs(A[i] - C[i - N]));
		mn = max(mn, abs(A[i] - B[i - N]));
	}
	ans = min(ans, min(mx, mn));
	printf("%d\n", ans);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5932kb

input:

5
71039844 102827355 217531548 220229557 237972610 314010999 309303025 282414480 227324750 127910276
355992665 573821998 974848115 193721993 786455947
602158296 281786121 321727541 140763116 455641294

output:

288147297

result:

wrong answer 1st lines differ - expected: '660837116', found: '288147297'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #41:

score: 0
Wrong Answer
time: 3585ms
memory: 11216kb

input:

300000
619 2319 3493 3715 4353 4926 8022 14367 18919 23666 25565 25582 27245 27303 28880 29568 29918 31815 34986 36861 40022 40147 47041 52120 55624 57816 58553 59319 60056 63512 66442 68907 68915 69471 69714 71129 76758 76761 77220 78196 84558 87950 88697 88782 89810 90113 92091 95040 97273 99148 1...

output:

792

result:

wrong answer 1st lines differ - expected: '167936427', found: '792'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%