QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#641383#7689. Flipping Cardsucup-team2526WA 1ms5640kbC++202.2kb2024-10-14 20:16:512024-10-14 20:16:53

Judging History

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

  • [2024-10-14 20:16:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5640kb
  • [2024-10-14 20:16:51]
  • 提交

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] >> b[i];
		c.push_back(a[i]);
                c.push_back(a[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: 5640kb

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: 5632kb

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

1
212055293 384338286

output:

212055293

result:

wrong answer 1st numbers differ - expected: '384338286', found: '212055293'