QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#619330#2442. Welcome Partyuntitledtwo#WA 430ms11396kbC++171.7kb2024-10-07 13:53:472024-10-07 13:53:49

Judging History

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

  • [2024-10-07 13:53:49]
  • 评测
  • 测评结果:WA
  • 用时:430ms
  • 内存:11396kb
  • [2024-10-07 13:53:47]
  • 提交

answer

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

const int MAXN = 200005;
typedef long long ll;
typedef pair<ll, ll> PR;
#define fi first
#define se second
#define PB push_back
#define MP make_pair

pair<ll, ll> a[MAXN];
set<ll> Set;
ll mx[MAXN];

signed main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
#endif
	int Case;
	scanf("%d", &Case);
	while (Case --) {
		int n;
		scanf("%d", &n);
		for (int i = 1; i <= n ; ++ i) scanf("%lld%lld", &a[i].fi, &a[i].se);
		sort(a + 1, a + n + 1, [&](PR a, PR b){ return (a.fi > b.fi) || (a.fi == b.fi && a.se < b.se); });
		ll ans = (ll)1e19;
		Set.clear();
		for (int i = 1; i <= n ; ++ i) mx[i] = max(mx[i - 1], a[i].se);
		for (int i = n; i >= 1 ; -- i) {
			ll t = mx[i - 1];
			auto nxt = Set.lower_bound(a[i].fi), pre = nxt;
			if (pre != Set.begin()) {
				-- pre;
				if (abs(t - a[i].fi) > abs(*pre - a[i].fi)) t = *pre;
			}
			if (nxt != Set.end()) {
				if (abs(t - a[i].fi) > abs(*nxt - a[i].fi)) t = *nxt;
			}
			ans = min(ans, abs(t - a[i].fi));
			Set.insert(a[i].se);
		}

		Set.clear();
		sort(a + 1, a + n + 1, [&](PR a, PR b){ return (a.fi > b.fi) || (a.fi == b.fi && a.se > b.se); });
		for (int i = 1; i <= n ; ++ i) mx[i] = max(mx[i - 1], a[i].se);
		for (int i = n; i >= 1 ; -- i) {
			ll t = mx[i - 1];
			auto nxt = Set.lower_bound(a[i].fi), pre = nxt;
			if (pre != Set.begin()) {
				-- pre;
				if (abs(t - a[i].fi) > abs(*pre - a[i].fi)) t = *pre;
			}
			if (nxt != Set.end()) {
				if (abs(t - a[i].fi) > abs(*nxt - a[i].fi)) t = *nxt;
			}
			ans = min(ans, abs(t - a[i].fi));
			Set.insert(a[i].se);
		}
		printf("%lld\n", ans);
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 430ms
memory: 11396kb

input:

66
5
27 46
89 13
55 8
71 86
22 35
3
3 5
4 7
6 2
2
0 1000000000
1000000000 0
2
1000000000 0
0 1000000000
2
1000000000 0
1000000000 0
2
0 1000000000
0 1000000000
2
1000000000 1000000000
0 0
2
0 0
0 0
2
1000000000 1000000000
1000000000 1000000000
3
90 30
90 50
90 85
3
0 0
0 2
0 5
3
20 30
20 50
20 70
3
...

output:

3
1
0
0
1000000000
0
1000000000
0
0
5
0
10
5
10
3
0
10
5
0
5
0
10
5
10
3
0
10
5
0
103423049738487445
10974087366700578
21076180420813408
183538167814754058
46751451188711820
58292659298928172
23639646046527434
4640409712116377
270663364266559542
139940820548070767
21494649603533736
10020053628568865...

result:

wrong answer 6th lines differ - expected: '1000000000', found: '0'