답안 #110200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110200 2019-05-10T07:29:02 Z hugo_pm Bali Sculptures (APIO15_sculpture) C++17
0 / 100
5 ms 2560 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a-1); i >= (b); --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second

const long long BIG = 1000000000000000000LL;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

void solve();
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

const int borneSuj = 30*1000 + 5;
const int borneTab = 3*borneSuj;
int gt[borneSuj][400];

int nbPlaces, nbDoges, nbNoeuds;
int limSqd;

vector<pii> adj[borneTab];

void solve()
{
	cin >> nbPlaces >> nbDoges;
	nbNoeuds = nbPlaces;
	limSqd = sqrt(nbPlaces);
	if (limSqd+1 < nbPlaces) ++limSqd;

	form2(distance, 1, limSqd) {
		form(ini, distance) {
			for (int place = ini; place < nbPlaces; place += distance) {
				int corNod = nbNoeuds; ++nbNoeuds;
				adj[corNod].push_back({place, 0});
				gt[place][distance] = corNod;

				if (place != ini) {
					adj[corNod].push_back({corNod-1, 1});
					adj[corNod-1].push_back({corNod, 1});
				}
			}
		}
	}

	form(iDoge, nbDoges) {
		int pos, saut;
		cin >> pos >> saut;
		if (saut < limSqd) {
			adj[pos].push_back({gt[pos][saut], 0});
		} else {
			for (int dd = 1; pos + dd*saut < nbPlaces; ++dd) {
				adj[pos].push_back({pos+dd*saut, dd});
			}

			for (int dd = 1; pos - dd*saut >= 0; ++dd) {
				adj[pos].push_back({pos - dd*saut, dd});
			}
		}
	}

	vector<int> md(nbNoeuds, BIG);
	md[0] = 0;
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	pq.push({0,0});
	while (! pq.empty()) {
		int dis = pq.top().fi, nod = pq.top().se;
		pq.pop();
		if (dis != md[nod]) continue;

		if (nod == 1) { cout << dis << "\n"; return; }

		for (auto voRaw : adj[nod]) {
			int vo = voRaw.fi, poids = voRaw.se;
			if (dis + poids < md[vo]) {
				md[vo] = dis+poids;
				pq.push({md[vo], vo});
			}
		}
	}

	cout << "-1\n";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 2560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 2432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 2464 KB Output isn't correct
2 Halted 0 ms 0 KB -