QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#475923#5540. City HallThirvinWA 176ms25404kbC++202.9kb2024-07-13 17:09:402024-07-13 17:09:41

Judging History

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

  • [2024-07-13 17:09:41]
  • 评测
  • 测评结果:WA
  • 用时:176ms
  • 内存:25404kb
  • [2024-07-13 17:09:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll = long long;
using pii = pair<ll,ll>;
struct L{
	ll m, k;
	L(){

	}
	L(ll n, ll k){
		this->m = n;
		this->k = k;
	}
	ll get(ll x){
		return 0ll + m * x + k;
	}
};
using piL = pair<ll,L>;
ll banana(L a, L b){
	return (b.k - a.k + (a.m - b.m - 1)) / (a.m - b.m) ; 
}
void solve(){
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	vector<int> h(n+1);
	for(int i = 1;i <= n;i ++)
		cin >> h[i];

	vector<vector<int>> v(n+1);
	for(int i = 0;i < m;i ++){
		int a,b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	vector<bool> vis(n+1);
	vector<ll> d1(n+1, 1e11);
	vector<ll> d2(n+1, 1e11);
	d1[s] = 0;
	d2[t] = 0;
	pq.emplace(0, s);
	while(pq.size() > 0){
		auto cur = pq.top();
		pq.pop();
		if(vis[cur.second])
			continue;
		vis[cur.second] = 1;
		for(int i : v[cur.second]){
			if(vis[i])
				continue;
			ll nx = cur.first + (h[i] - h[cur.second]) * (h[i] - h[cur.second]);
			if(nx < d1[i]){
				d1[i] = nx;
				pq.emplace(nx, i);
			}
		}
	}
	vis.clear();
	vis.resize(n+1);
	pq.emplace(0, t);
	while(pq.size() > 0){
		auto cur = pq.top();
		pq.pop();
		if(vis[cur.second])
			continue;
		vis[cur.second] = 1;

		for(int i : v[cur.second]){
			if(vis[i])
				continue;

			ll nx = cur.first + (h[i] - h[cur.second]) * (h[i] - h[cur.second]);
			if(nx < d2[i]){
				d2[i] = nx;
				pq.emplace(nx, i);
			}
		}
	}

	ll ans = 2*d1[t];

	for(int i = 1;i <= n;i ++){
		if(i == s || i == t){
			ll rec = 1e11;

			for(int it : v[i]){
				if(i == s)
					rec = min(rec, d2[it]*2);
				else
					rec = min(rec, d1[it]*2);
			}
			ans = min(ans, rec);
			continue;
		}
		deque<pair<int, L>> dq;
		set<pii> st;
		for(int it : v[i])
			st.emplace(h[it], it);
		map<int,int> mp;
		ll rec = 1e11;
		for(pii i : st){
			if(mp[i.first])
				continue;
			mp[i.first] = 1;
			L nx(-2 * i.first, 2*d2[i.second] + i.first * i.first);
			if(dq.size() == 0){
				dq.emplace_back(1e9, nx);
				continue;
			}
			
			while(dq.size() > 1){
				auto cur = dq.back();
				ll tmp = banana(cur.second, nx);
				if(tmp <= dq[dq.size()-2].first){
					dq[dq.size()-2].first = banana(nx, dq[dq.size()-2].second);
					dq.pop_back();
				}else{
					break;
				}
			}
			ll x = banana(nx, dq.back().second); 
			dq.back().first = x;
			dq.emplace_back(1e9, nx);
		}
		for(int p : v[i]){
			int l = 0;
			int r = dq.size();
			while(r - l > 1){
				int mid = (r + l) / 2;
				if(dq[mid].first >= h[p]){
					r = mid;
				}else{
					l = mid;
				}
			}
			rec = min(rec,  2*d1[p] + h[p] * h[p] + dq[r].second.get(h[p]));
		}
		ans = min(rec, ans);
	}
	cout << double(ans) / 2 << "\n";
}
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	cout<<fixed << setprecision(6) ;
	int t = 1;
//	cin >> t;
	while(t--){
		solve();
	}
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3788kb

input:

5 6 1 3
5 100 8 2 10
1 2
2 3
2 5
1 4
4 5
3 5

output:

4.500000

result:

ok found '4.5000000', expected '4.5000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

5 5 1 5
1 2 10 10 4
1 2
2 3
2 4
3 5
4 5

output:

3.000000

result:

ok found '3.0000000', expected '3.0000000', error '0.0000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

5 4 1 4
8 8 8 8 100
1 2
2 3
3 4
4 5

output:

0.000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

2 1 1 2
0 100000
1 2

output:

0.000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #5:

score: 0
Accepted
time: 159ms
memory: 14464kb

input:

632 199396 167 549
22513 93521 41403 35441 97617 53210 62622 4751 81863 14470 2994 93092 40432 30872 34423 36577 92540 92961 4110 14691 83321 10680 89112 80890 31108 24492 8973 42636 33792 27400 82361 85003 68940 31221 48625 276 52755 6649 34381 54399 6063 22628 17715 54052 58175 86609 82622 29917 9...

output:

0.000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #6:

score: 0
Accepted
time: 131ms
memory: 10564kb

input:

600 179700 396 574
83219 94660 9266 1939 32637 7117 33396 76947 42614 41001 87026 60210 25868 36044 35276 6147 36198 25195 50981 68230 32619 62563 28509 46643 43304 36195 99724 30903 77230 57923 36939 81397 17374 90947 48623 38120 48914 96481 98146 31707 9427 58735 82986 31328 94507 69081 51908 4188...

output:

0.000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #7:

score: 0
Accepted
time: 138ms
memory: 15032kb

input:

100000 200000 66364 98254
48399 8344 35365 18555 95271 13113 75220 25062 73969 71647 58212 68205 36310 45496 6965 59960 71592 81323 44341 95796 61521 63298 77830 16145 73103 83477 85246 53680 67289 68475 64978 43576 18969 28023 22848 55164 31276 12825 70999 49142 77203 40134 88148 59337 2357 70519 8...

output:

1019365473.000000

result:

ok found '1019365473.0000000', expected '1019365473.0000000', error '0.0000000'

Test #8:

score: 0
Accepted
time: 136ms
memory: 15816kb

input:

100000 200000 21412 38673
24050 75090 3692 20770 26840 57646 61096 3013 66291 73437 83126 67768 92979 69169 9389 70447 17151 74737 33407 3128 78504 52736 45853 27090 64395 24808 83577 24168 38576 37445 71022 40066 34908 90579 58370 31436 69812 39811 83370 50254 6518 72740 79316 67247 22759 65630 564...

output:

0.000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #9:

score: -100
Wrong Answer
time: 176ms
memory: 25404kb

input:

100000 200000 75283 45047
38593 5224 81049 28255 11324 43744 51172 60916 67783 62336 96782 50029 48743 18780 32756 4774 32484 95733 17336 38046 98145 49655 68352 58308 21594 64540 11719 57827 30130 70076 95133 29886 93864 22677 28498 60413 44567 78935 64952 88954 85786 34019 75159 69192 15108 54645 ...

output:

449627765.000000

result:

wrong answer 1st numbers differ - expected: '6010044.5000000', found: '449627765.0000000', error = '73.8127181'