Submission #426135

# Submission time Handle Problem Language Result Execution time Memory
426135 2021-06-13T14:35:53 Z alishahali1382 Sky Walking (IOI19_walk) C++14
10 / 100
57 ms 8700 KB
#include "walk.h"
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debug2(x, y) {cerr<<"{"<<#x<<", "<<#y<<"}={"<<x<<", "<<y<<"}\n";}
#define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";}
#define debugv(abcd) {cerr<<#abcd<<": ";for (auto dcba:abcd) cerr<<dcba<<", ";cerr<<"\n";}
#define pb push_back
#define SZ(x) ((int)x.size())
#define all(x) x.begin(), x.end()

const int inf=1000001000; // 1e9
const ll INF=10000000010000000; // 1e16
const int mod=1000000007;
const int MAXN=100010, LOG=9;

int n, m, k, x, y, u, v;
ll dist[51][101];
bool mark[51][101];
vi comp;
priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> pq;

inline void upd(int x, int y, ll d){ if (dist[x][y]>d) pq.push({dist[x][y]=d, {x, y}});}

ll min_distance(vi X, vi H, vi L, vi R, vi Y, int s, int g){
	n=SZ(X);
	m=SZ(L);
	for (int i=0; i<n; i++) comp.pb(H[i]);
	for (int i=0; i<m; i++) comp.pb(Y[i]);
	comp.pb(0);
	sort(all(comp));
	comp.resize(unique(all(comp))-comp.begin());
	memset(dist, 63, sizeof(dist));
	pq.push({dist[s][0]=0, {s, 0}});
	while (pq.size()){
		pii p=pq.top().second;
		pq.pop();
		int x=p.first, h=p.second;
		if (mark[x][h]) continue ;
		// cerr<<X[x]<<" "<<comp[h]<<"  "<<dist[x][h]<<"\n";
		mark[x][h]=1;
		if (H[x]>comp[h]) upd(x, h+1, dist[x][h]+comp[h+1]-comp[h]);
		if (H[x]>=comp[h] && h) upd(x, h-1, dist[x][h]+comp[h]-comp[h-1]);
		for (int i=0; i<m; i++) if (Y[i]==comp[h] && L[i]<x && x<=R[i]){
			upd(x-1, h, dist[x][h]+X[x]-X[x-1]);
			break ;
		}
		for (int i=0; i<m; i++) if (Y[i]==comp[h] && L[i]<=x && x<R[i]){
			upd(x+1, h, dist[x][h]+X[x+1]-X[x]);
			break ;
		}
	}

	if (dist[g][0]>=INF) return -1;
	return dist[g][0];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Runtime error 45 ms 8700 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 4428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 4428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Runtime error 45 ms 8700 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -