QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#619253#2442. Welcome Partyuntitledtwo#WA 385ms13212kbC++171.7kb2024-10-07 13:39:222024-10-07 13:39:25

Judging History

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

  • [2024-10-07 13:39:25]
  • 评测
  • 测评结果:WA
  • 用时:385ms
  • 内存:13212kb
  • [2024-10-07 13:39:22]
  • 提交

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 = -(ll)1e19;
			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(max(mx[i - 1], 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 = -(ll)1e19;
			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(max(mx[i - 1], t) - a[i].fi));
			Set.insert(a[i].se);
		}
		printf("%lld\n", ans);
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 385ms
memory: 13212kb

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
1000000000
1000000000
0
0
5
0
10
5
10
3
0
10
5
0
5
0
10
5
10
3
0
10
5
0
146595730144168239
13421384895232913
319085902357172449
97841672516941208
46751451188711820
100350251118705401
23639646046527434
40476687889457528
215220133813519115
126071583084090326
51973741711666211
100200...

result:

wrong answer 31st lines differ - expected: '10974087366700578', found: '13421384895232913'