답안 #1071470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1071470 2024-08-23T07:37:32 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++){
				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(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:25: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]
   25 |   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:54:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int j = 0;j<all.size();j++)mp[pii(i,j)] = mp.size();
      |                 ~^~~~~~~~~~~
walk.cpp:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int j = 0;j<all.size();j++){
      |                 ~^~~~~~~~~~~
walk.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |    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++){
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Incorrect 3 ms 7004 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Execution timed out 4131 ms 1010792 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 20264 KB Output is correct
2 Execution timed out 4038 ms 1048576 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 20264 KB Output is correct
2 Execution timed out 4038 ms 1048576 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Incorrect 3 ms 7004 KB Output isn't correct
5 Halted 0 ms 0 KB -