QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#247586#7689. Flipping Cardsucup-team1074WA 1ms7548kbC++20950b2023-11-11 15:01:252023-11-11 15:01:26

Judging History

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

  • [2023-11-11 15:01:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7548kb
  • [2023-11-11 15:01:25]
  • 提交

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 check(int x) {
	int y = (n + 1) / 2 - 1;
	int cnt = 0;
	int maxx = 0;
	//最少能有多少个比x小的数
	for (int i = 1; i <= n; i++) {
		if(c[i].first < x){
			cnt++;
			if(c[i].second >= x){
				maxx ++;//[L,R]的最大贡献
			}
		}
		if(c[i].first >= x){
			if(c[i].second < x){
				maxx -= 1;
			}
			maxx = max(0 , maxx);
		}
		
	}
	return cnt - maxx <= y;
}
int main () {
	cin >> n;
	set<int>st;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		c[i] = {a[i], b[i]};
		st.insert(a[i]);
		st.insert(b[i]);
	}
	vector<int>v;
	for(auto it : st){
		v.push_back(it);
	}
	int l = 0 , r = v.size() - 1;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (check(v[mid])) l = mid;
		else r = mid - 1;
	}
	cout << v[l] << endl;
	return 0;
}

详细

Test #1:

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

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

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

1
212055293 384338286

output:

384338286

result:

ok 1 number(s): "384338286"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 7548kb

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:

507346252

result:

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