답안 #417091

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417091 2021-06-03T11:39:44 Z Kevin_Zhang_TW Sky Walking (IOI19_walk) C++17
0 / 100
203 ms 123436 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif


// TODO Watch out for the size
const int MAX_N = 400010;
const ll inf = 1ll << 55;
#include "walk.h"

// graph is 0 based
int n, m;
vector<int> xup[MAX_N];
vector<int> x, h, pfsz;
vector<pair<int,int>> edge[MAX_N];

int get_id(int i, int j) {
	return lower_bound(AI(xup[i]), j) - begin(xup[i]) + pfsz[i];
}

void init_ver() {
	pfsz.resize(n+1);
	for (int i = 0;i < n;++i) {
		sort(AI(xup[i]));
		xup[i].erase(unique(AI(xup[i])), end(xup[i]));

		pfsz[i+1] = pfsz[i] + xup[i].size();
		for (int j = 1;j < xup[i].size();++j) {
			int a = pfsz[i]+j-1, b = pfsz[i] + j
			//int a = get_id(i, xup[i][j-1]), b = get_id(i, xup[i][j]),
				, d = xup[i][j] - xup[i][j-1];
			edge[a].pb(b, d);
			edge[b].pb(a, d);
		}
	}

	for (int i = 0;i < n;++i)
		for (int y : xup[i])
			DE(i, y, get_id(i, y));
}

void mbuild(vector<int> l, vector<int> r, vector<int> y) {
	for (int i = 0;i < m;++i) {
		//DE(l[i], r[i], y[i]);
		vector< int > loc;
		for (int j = l[i];j <= r[i];++j) {
			//DE(j, h[j]);
			if (h[j] < y[i]) continue;

			loc.pb( j );
		}
		for (int j = 1;j < loc.size();++j) {
			int a = get_id(loc[j-1], y[i]), b = get_id(loc[j], y[i]),
				d = x[ loc[j] ] - x[ loc[j-1] ];
		
			edge[a].pb(b, d);
			edge[b].pb(a, d);
		}
	}
}

ll sho(int s, int t) {
	int V = pfsz.back() + 10;
	vector<ll> dis(V, inf);
	
	priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;
	auto upd = [&](int id, ll d) {
		if (chmin(dis[id], d))
			pq.emplace(d, id);
	};

	upd(s, 0);

	while (pq.size()) {
		auto [d, x] = pq.top(); pq.pop();
		if (d != dis[x]) continue;
		DE(x, d);
		for (auto [u, w] : edge[x])
			upd(u, d + w);
	}
	return dis[t];

}

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) {
	n = x.size();
	m = l.size();
	::x = x;
	::h = h;

	for (int i = 0;i < m;++i) {
		for (int j = l[i];j <= r[i];++j) {
			if (h[j] < y[i]) continue;
			xup[j].pb(y[i]);
		}
	}
	xup[s].pb(0), xup[g].pb(0);

	DE(s, g);

	init_ver();

	mbuild(l, r, y);

	return sho( get_id(s, 0), get_id(g, 0) );
}

Compilation message

walk.cpp: In function 'void init_ver()':
walk.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for (int j = 1;j < xup[i].size();++j) {
      |                  ~~^~~~~~~~~~~~~~~
walk.cpp:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
walk.cpp:52:4: note: in expansion of macro 'DE'
   52 |    DE(i, y, get_id(i, y));
      |    ^~
walk.cpp:51:12: warning: unused variable 'y' [-Wunused-variable]
   51 |   for (int y : xup[i])
      |            ^
walk.cpp: In function 'void mbuild(std::vector<int>, std::vector<int>, std::vector<int>)':
walk.cpp:65:20: 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 = 1;j < loc.size();++j) {
      |                  ~~^~~~~~~~~~~~
walk.cpp: In function 'll sho(int, int)':
walk.cpp:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
walk.cpp:90:3: note: in expansion of macro 'DE'
   90 |   DE(x, d);
      |   ^~
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:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
walk.cpp:112:2: note: in expansion of macro 'DE'
  112 |  DE(s, g);
      |  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19020 KB Output is correct
2 Correct 12 ms 19056 KB Output is correct
3 Correct 11 ms 19020 KB Output is correct
4 Incorrect 12 ms 19024 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 18976 KB Output is correct
2 Correct 11 ms 19020 KB Output is correct
3 Runtime error 146 ms 78328 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 25284 KB Output is correct
2 Runtime error 203 ms 123436 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 25284 KB Output is correct
2 Runtime error 203 ms 123436 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19020 KB Output is correct
2 Correct 12 ms 19056 KB Output is correct
3 Correct 11 ms 19020 KB Output is correct
4 Incorrect 12 ms 19024 KB Output isn't correct
5 Halted 0 ms 0 KB -