QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#247273#7689. Flipping Cardsucup-team1074WA 1ms7672kbC++20858b2023-11-11 13:52:462023-11-11 13:52:46

Judging History

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

  • [2023-11-11 13:52:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7672kb
  • [2023-11-11 13:52:46]
  • 提交

answer

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

const int N = 3e5 + 10;
typedef pair<int, int> PII;
int a[N], b[N];
PII c[N];
int idx[N];
int n;
bool cmp (int x, int y) {
	return c[x] < c[y];
}

bool check(int x) {
	int y = x - 1 - (n - 1) / 2;
	int cnt = 0;
	for (int i = 1; i < x; i++) {
		if (c[idx[i]].second >= c[idx[x]].first)
			cnt++;
	}
	return cnt >= y;


}


int main () {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		c[i] = { a[i], b[i] };
		idx[i] = i;
	}
	sort (idx + 1, idx + n + 1, cmp);
	// for (int i = 1; i <= n; i++) {
	// 	cout << c[idx[i]].first << " " << c[idx[i]].second << endl;
	// }

	int l = ((n + 1) / 2), r = n;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	cout << c[idx[l]].first << endl;



	return 0;
}

详细

Test #1:

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

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: 0ms
memory: 7672kb

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

1
212055293 384338286

output:

212055293

result:

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