#pragma optimize("Bismilahirrahmanirrahim")
//█▀█─█──█──█▀█─█▀█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
//Sani buyuk Osman Pasa Plevneden cikmam diyor
#define author tolbi
#include <bits/stdc++.h>
using namespace std;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define vint(x) vector<int> x
#define sortarr(x) sort(x.begin(), x.end())
#define sortrarr(x) sort(x.rbegin(), x.rend())
#define tol(bi) (1LL<<((int)(bi)))
typedef long long ll;
const int MOD = 1e9+7;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
#include "walk.h"
long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) {
ll n = x.size();
ll m = y.size();
vector<ll> lelx(n);
iota(lelx.begin(), lelx.end(), 0);
vector<ll> lely(m,-1);
vector<array<ll,4>> isl;
for (ll i = 0; i < m; i++){
isl.push_back({l[i],y[i],i,1});
isl.push_back({r[i]+1,y[i],i,-1});
}
sortarr(isl);
ll indi = 0;
set<pair<ll,ll>> st;
vector<vector<pair<ll,ll>>> arr(n);
vector<ll> xpos(n);
for (ll i = 0; i < n; ++i)
{
xpos[i]=x[i];
}
vector<ll> ypos(n,0);
for (ll i = 0; i < n; i++){
while (indi<isl.size() && isl[indi][0]<=i){
if (isl[indi][3]==1){
st.insert({isl[indi][1],isl[indi][2]});
}
else {
st.erase({isl[indi][1],isl[indi][2]});
}
indi++;
}
auto it = st.begin();
while (it!=st.end()){
if (it->first>h[i]) break;
ll node = arr.size();
xpos.push_back(x[i]);
ypos.push_back(it->first);
arr.push_back(vector<pair<ll,ll>>());
if (lely[it->second]!=-1){
arr[lely[it->second]].push_back({node,abs(xpos[node]-xpos[lely[it->second]])});
arr[node].push_back({lely[it->second],abs(xpos[node]-xpos[lely[it->second]])});
}
arr[lelx[i]].push_back({node,abs(ypos[node]-ypos[lelx[i]])});
arr[node].push_back({lelx[i],abs(ypos[node]-ypos[lelx[i]])});
lelx[i]=node;
lely[it->second]=node;
it++;
}
}
vector<ll> dp(arr.size(), -1);
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
pq.push({0,s});
while (pq.size()){
ll node = pq.top().second;
ll w = pq.top().first;
pq.pop();
if (dp[node]!=-1) continue;
dp[node]=w;
for (ll i = 0; i < arr[node].size(); i++){
if (dp[arr[node][i].first]!=-1) continue;
pq.push({w+arr[node][i].second,arr[node][i].first});
}
}
return dp[g];
}
Compilation message
walk.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
1 | #pragma optimize("Bismilahirrahmanirrahim")
|
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:46:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::array<long long int, 4> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | while (indi<isl.size() && isl[indi][0]<=i){
| ~~~~^~~~~~~~~~~
walk.cpp:82:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for (ll i = 0; i < arr[node].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
276 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
416 ms |
99480 KB |
Output is correct |
4 |
Correct |
397 ms |
118668 KB |
Output is correct |
5 |
Correct |
213 ms |
95088 KB |
Output is correct |
6 |
Correct |
206 ms |
85288 KB |
Output is correct |
7 |
Correct |
241 ms |
95212 KB |
Output is correct |
8 |
Correct |
533 ms |
125608 KB |
Output is correct |
9 |
Correct |
296 ms |
100448 KB |
Output is correct |
10 |
Correct |
567 ms |
148444 KB |
Output is correct |
11 |
Correct |
224 ms |
60752 KB |
Output is correct |
12 |
Correct |
164 ms |
45772 KB |
Output is correct |
13 |
Correct |
490 ms |
131244 KB |
Output is correct |
14 |
Correct |
140 ms |
43632 KB |
Output is correct |
15 |
Correct |
165 ms |
45884 KB |
Output is correct |
16 |
Correct |
134 ms |
45748 KB |
Output is correct |
17 |
Correct |
134 ms |
44056 KB |
Output is correct |
18 |
Correct |
160 ms |
54212 KB |
Output is correct |
19 |
Correct |
8 ms |
2724 KB |
Output is correct |
20 |
Correct |
58 ms |
22444 KB |
Output is correct |
21 |
Correct |
137 ms |
42776 KB |
Output is correct |
22 |
Correct |
149 ms |
44868 KB |
Output is correct |
23 |
Correct |
196 ms |
58872 KB |
Output is correct |
24 |
Correct |
155 ms |
45040 KB |
Output is correct |
25 |
Correct |
148 ms |
44320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
19380 KB |
Output is correct |
2 |
Correct |
2700 ms |
650536 KB |
Output is correct |
3 |
Runtime error |
1633 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
19380 KB |
Output is correct |
2 |
Correct |
2700 ms |
650536 KB |
Output is correct |
3 |
Runtime error |
1633 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
276 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
432 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
416 ms |
99480 KB |
Output is correct |
21 |
Correct |
397 ms |
118668 KB |
Output is correct |
22 |
Correct |
213 ms |
95088 KB |
Output is correct |
23 |
Correct |
206 ms |
85288 KB |
Output is correct |
24 |
Correct |
241 ms |
95212 KB |
Output is correct |
25 |
Correct |
533 ms |
125608 KB |
Output is correct |
26 |
Correct |
296 ms |
100448 KB |
Output is correct |
27 |
Correct |
567 ms |
148444 KB |
Output is correct |
28 |
Correct |
224 ms |
60752 KB |
Output is correct |
29 |
Correct |
164 ms |
45772 KB |
Output is correct |
30 |
Correct |
490 ms |
131244 KB |
Output is correct |
31 |
Correct |
140 ms |
43632 KB |
Output is correct |
32 |
Correct |
165 ms |
45884 KB |
Output is correct |
33 |
Correct |
134 ms |
45748 KB |
Output is correct |
34 |
Correct |
134 ms |
44056 KB |
Output is correct |
35 |
Correct |
160 ms |
54212 KB |
Output is correct |
36 |
Correct |
8 ms |
2724 KB |
Output is correct |
37 |
Correct |
58 ms |
22444 KB |
Output is correct |
38 |
Correct |
137 ms |
42776 KB |
Output is correct |
39 |
Correct |
149 ms |
44868 KB |
Output is correct |
40 |
Correct |
196 ms |
58872 KB |
Output is correct |
41 |
Correct |
155 ms |
45040 KB |
Output is correct |
42 |
Correct |
148 ms |
44320 KB |
Output is correct |
43 |
Correct |
56 ms |
19380 KB |
Output is correct |
44 |
Correct |
2700 ms |
650536 KB |
Output is correct |
45 |
Runtime error |
1633 ms |
1048576 KB |
Execution killed with signal 9 |
46 |
Halted |
0 ms |
0 KB |
- |