Submission #1071467

# Submission time Handle Problem Language Result Execution time Memory
1071467 2024-08-23T07:35:00 Z pcc Sky Walking (IOI19_walk) C++17
0 / 100
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>


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;
				if(d+w<dist[nxt]){
					dist[nxt] = d+w;
					pq.push(pll(d+w,nxt));
				}
			}
		}
		return;
	}
}

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) {
	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++){
				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(s,0)]] = 0;
	//cerr<<mp[pii(s,0)]<<','<<mp[pii(g,0)]<<endl;
	DIJKSTRA::GO();
	return dist[mp[pii(g,0)]];
}

Compilation message

walk.cpp: In function 'void DIJKSTRA::GO()':
walk.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<std::pair<int, int>, 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>, int, int)':
walk.cpp:55:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int j = 0;j<all.size();j++)mp[pii(i,j)] = mp.size();
      |                 ~^~~~~~~~~~~
walk.cpp:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   for(int j = 0;j<all.size();j++){
      |                 ~^~~~~~~~~~~
walk.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |    for(int k = j+1;k<all.size();k++){
      |                    ~^~~~~~~~~~~
walk.cpp:74:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |  for(int i = 0;i<l.size();i++){
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6552 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Incorrect 4 ms 7772 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 6492 KB Output is correct
3 Runtime error 3927 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 20300 KB Output is correct
2 Execution timed out 4008 ms 1048576 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 20300 KB Output is correct
2 Execution timed out 4008 ms 1048576 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6552 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Incorrect 4 ms 7772 KB Output isn't correct
5 Halted 0 ms 0 KB -