# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1071481 |
2024-08-23T07:43:30 Z |
pcc |
Sky Walking (IOI19_walk) |
C++17 |
|
4000 ms |
1048576 KB |
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define _all(T) T.begin(),T.end()
#define ll long long
#define pii pair<int,int>
#define fs first
#define sc second
#define pll pair<ll,ll>
#define int ll
const int mxn = 2e5+10;
const ll inf = 1e18;
vector<pii> paths[mxn];
vector<int> all;
map<pii,int> mp;
ll dist[mxn];
int N;
namespace DIJKSTRA{
priority_queue<pll,vector<pll>,greater<pll>> pq;
bitset<mxn> vis;
void GO(){
vis.reset();
for(int i = 0;i<mp.size();i++){
pq.push(pll(dist[i],i));
}
while(!pq.empty()){
auto [d,now] = pq.top();
pq.pop();
if(vis[now])continue;
//cerr<<now<<":"<<d<<endl;
vis[now] = true;
for(auto [nxt,w]:paths[now]){
if(vis[nxt])continue;
assert(w>=0);
if(d+w<dist[nxt]){
dist[nxt] = d+w;
pq.push(pll(d+w,nxt));
}
}
}
return;
}
}
long long min_distance(std::vector<int32_t> x, std::vector<int32_t> H, std::vector<int32_t> l, std::vector<int32_t> r, std::vector<int32_t> y, int32_t st, int32_t ed) {
all.push_back(0);
N = x.size();
for(auto &i:H)all.push_back(i);
for(auto &i:y)all.push_back(i);
sort(_all(all));
all.resize(unique(_all(all))-all.begin());
for(int i = 0;i<N;i++){
for(int j = 0;j<all.size();j++)mp[pii(i,j)] = mp.size();
}
assert(mp.size()<mxn);
/*
for(auto &i:mp){
cerr<<i.fs.fs<<','<<all[i.fs.sc]<<":"<<i.sc<<endl;
}
*/
for(int i = 0;i<N;i++){
for(int j = 0;j<all.size();j++){
for(int k = j+1;k<all.size();k++){
if(H[i]<all[k])break;
int a = mp[pii(i,j)],b = mp[pii(i,k)];
paths[a].push_back(pii(b,abs(all[j]-all[k])));
paths[b].push_back(pii(a,abs(all[j]-all[k])));
}
}
}
for(int i = 0;i<l.size();i++){
int s = l[i],e = r[i],h = y[i];
h = lower_bound(_all(all),h)-all.begin();
assert(all[h] == y[i]);
pii pre = pii(s,h);
for(int j = s+1;j<=e;j++){
if(H[j]<all[h])continue;
pii now = pii(j,h);
int a = mp[pre],b = mp[now];
assert(x[now.fs]>=x[pre.fs]);
paths[a].push_back(pii(b,x[now.fs]-x[pre.fs]));
paths[b].push_back(pii(a,x[now.fs]-x[pre.fs]));
pre = now;
}
}
fill(dist,dist+mxn,inf);
dist[mp[pii(st,0)]] = 0;
//cerr<<mp[pii(st,0)]<<','<<mp[pii(ed,0)]<<endl;
DIJKSTRA::GO();
return dist[mp[pii(ed,0)]];
}
Compilation message
walk.cpp: In function 'void DIJKSTRA::GO()':
walk.cpp:26:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::map<std::pair<long long int, long long int>, long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = 0;i<mp.size();i++){
| ~^~~~~~~~~~
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int32_t, int32_t)':
walk.cpp:56:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int j = 0;j<all.size();j++)mp[pii(i,j)] = mp.size();
| ~^~~~~~~~~~~
walk.cpp:67:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int j = 0;j<all.size();j++){
| ~^~~~~~~~~~~
walk.cpp:68:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int k = j+1;k<all.size();k++){
| ~^~~~~~~~~~~
walk.cpp:77:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int i = 0;i<l.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6744 KB |
Output is correct |
4 |
Incorrect |
4 ms |
7260 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6700 KB |
Output is correct |
3 |
Execution timed out |
4126 ms |
1028456 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
24904 KB |
Output is correct |
2 |
Runtime error |
3814 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
24904 KB |
Output is correct |
2 |
Runtime error |
3814 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6744 KB |
Output is correct |
4 |
Incorrect |
4 ms |
7260 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |