QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#641301#7689. Flipping Cardsucup-team2526WA 1ms5660kbC++202.2kb2024-10-14 19:43:022024-10-14 19:43:03

Judging History

你现在查看的是最新测评结果

  • [2024-10-14 19:43:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5660kb
  • [2024-10-14 19:43:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)

void err() {
	std::cout << std::endl;
}

template<class T, class... Ts>
void err(T arg, Ts &... args) {
	std::cout << fixed << setprecision(10) << arg << ' ';
	err(args...);
}

const int maxn = 3e5 + 5;
int a[maxn],b[maxn];
int n;

int check(int x) {
	vector<int> val(n + 5);
	vector<int>	dp(n + 5);
	int mi = 0,mx = 0,cnt1 = 0,cnt2 = 0;
	for (int i = 1;i <= n;i++) {
		if (a[i] <= x && b[i] <= x) {
			val[i] = 0;
			mi++,mx++;
		}
		else if (a[i] <= x && b[i] > x) {
			val[i] = -1;
			cnt1++;
		}
		else if (a[i] > x && b[i] <= x) {
			val[i] = 1;
			cnt2++;
		}
	}
	int res = 0,now = 0;
	for (int i = 1;i <= n;i++) {
		if (dp[i - 1] + val[i] > val[i]) {
			dp[i] = dp[i - 1] + val[i];
			if (val[i] == -1) now++;
		}
		else {
			dp[i] = val[i];
			now = 0;
		}
		if (dp[i] == -1) dp[i] = 0,now = 0;
		res = max(res,dp[i] + cnt1 - now);
	}
	mx += res;
	res = 0,now = 0;
 	for (int i = 1;i <= n;i++) {
		val[i] = -val[i];
		dp[i] = 0;
	}
	swap(cnt1,cnt2);
	for (int i = 1;i <= n;i++) {
		if (dp[i - 1] + val[i] >= val[i]) {
			dp[i] = dp[i - 1] + val[i];
			if (val[i] == -1) now++;
		}
		else {
			dp[i] = val[i];
			now = 0;
		}
		if (dp[i] == -1) {
			dp[i] = 0;
			now = 0;
		}
		res = max(res,dp[i] + now - cnt2);
	}
	mi -= res;
	if (n / 2 + 1 >= mi && n / 2 + 1 <= mx) return 1;
	else if (n / 2 + 1 < mi) {
		return 2;
	}
	else if (n / 2 + 1 > mx) {
		return 3;
	}
}

void GENSHEN_START() {
	cin >> n;
	vector<int>c;
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
		c.push_back(a[i]);
	}
	for (int i = 1;i <= n;i++) {
		cin >> b[i];
		c.push_back(b[i]);
	}
	sort(c.begin(),c.end());
	int len = c.size();
	int l = 0,r = len - 1;
	int ans = -1;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (check(c[mid]) == 1) {
			l = mid + 1;
			ans = max(ans,c[mid]);
		}
		else if (check(c[mid]) == 2) r = mid - 1;
		else if (check(c[mid]) == 3) l = mid + 1;
	}
	cout << ans;
}

signed main()
{
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int T = 1;
	//cin >> T;
	while (T--) GENSHEN_START();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5660kb

input:

5
3 6
5 2
4 7
6 4
2 8

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5660kb

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5564kb

input:

1
212055293 384338286

output:

384338286

result:

ok 1 number(s): "384338286"

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 5648kb

input:

99
749159996 323524232
125448341 365892333
481980673 143665393
394405973 44741918
687549448 513811513
287088118 385131171
11865696 666468353
449920567 373650719
671547289 116780561
41003675 671513243
351534153 507850962
374160874 985661954
222519431 600582098
987220654 704142246
856147059 37783620
1...

output:

718321536

result:

wrong answer 1st numbers differ - expected: '528957505', found: '718321536'