답안 #15874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
15874 2015-07-31T18:13:30 Z myungwoo Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
31 ms 11280 KB
#include <bits/stdc++.h>
using namespace std;

#define MAXN 30005
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;

int N, M, S, E;
int D[MAXN];
set <int> A[200][200];
vector <int> doge[MAXN];

int main()
{
	scanf("%d%d", &N, &M);
	for (int i=0;i<M;i++){
		int b, p;
		scanf("%d%d", &b, &p); doge[b].pb(p);
		if (!i) S = b;
		if (i == 1) E = b;
	}
	for (int i=0;i<N;i++) D[i] = 2e9;
	priority_queue <pii> que;
	D[S] = 0;
	que.push(mp(0, S));
	for (int i=0;i<N;i++) for (int j=1;j<200;j++) A[j][i%j].insert(i);
	while (!que.empty()){
		int q = que.top().second, d = -que.top().first; que.pop();
		if (D[q] != d) continue;
		if (q == E) break;
		for (int i=1;i<200;i++) A[i][q%i].erase(q);
		for (int p: doge[q]){
			if (p > 199){
				for (int i=q-p;i>=0;i-=p)
					if (D[i] > D[q]+(q-i)/p)
						D[i] = D[q]+(q-i)/p, que.push(mp(-D[i], i));
				for (int i=q+p;i>=0;i+=p)
					if (D[i] > D[q]+(i-q)/p)
						D[i] = D[q]+(i-q)/p, que.push(mp(-D[i], i));
			}else{
				int m = q % p;
				for (auto it=A[p][m].begin();it!=A[p][m].end();it++){
					if (D[*it] > D[q]+abs(*it-q)/p)
						D[*it] = D[q]+abs(*it-q)/p, que.push(mp(-D[*it], *it));
				}
			}
		}
	}
	printf("%d\n", D[E] < 2e9 ? D[E] : -1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4420 KB Output is correct
2 Correct 0 ms 4420 KB Output is correct
3 Correct 2 ms 4420 KB Output is correct
4 Correct 0 ms 4420 KB Output is correct
5 Correct 0 ms 4420 KB Output is correct
6 Correct 0 ms 4420 KB Output is correct
7 Correct 0 ms 4420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4420 KB Output is correct
2 Correct 0 ms 4420 KB Output is correct
3 Correct 2 ms 4420 KB Output is correct
4 Correct 0 ms 4420 KB Output is correct
5 Correct 0 ms 4420 KB Output is correct
6 Correct 0 ms 4420 KB Output is correct
7 Correct 2 ms 4420 KB Output is correct
8 Correct 2 ms 4684 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 0 ms 5344 KB Output is correct
11 Correct 2 ms 5344 KB Output is correct
12 Correct 6 ms 5344 KB Output is correct
13 Correct 5 ms 5344 KB Output is correct
14 Correct 3 ms 5344 KB Output is correct
15 Correct 3 ms 5344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4420 KB Output is correct
2 Correct 0 ms 4420 KB Output is correct
3 Correct 0 ms 4420 KB Output is correct
4 Correct 0 ms 4420 KB Output is correct
5 Correct 0 ms 4420 KB Output is correct
6 Correct 0 ms 4420 KB Output is correct
7 Correct 0 ms 4420 KB Output is correct
8 Correct 0 ms 4684 KB Output is correct
9 Correct 0 ms 4948 KB Output is correct
10 Correct 0 ms 5344 KB Output is correct
11 Correct 5 ms 5344 KB Output is correct
12 Correct 0 ms 5344 KB Output is correct
13 Correct 5 ms 5344 KB Output is correct
14 Correct 0 ms 5344 KB Output is correct
15 Correct 0 ms 5344 KB Output is correct
16 Correct 5 ms 6268 KB Output is correct
17 Runtime error 19 ms 11280 KB SIGSEGV Segmentation fault
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4420 KB Output is correct
2 Correct 0 ms 4420 KB Output is correct
3 Correct 0 ms 4420 KB Output is correct
4 Correct 0 ms 4420 KB Output is correct
5 Correct 0 ms 4420 KB Output is correct
6 Correct 0 ms 4420 KB Output is correct
7 Correct 0 ms 4420 KB Output is correct
8 Correct 0 ms 4684 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 4 ms 5344 KB Output is correct
11 Correct 4 ms 5344 KB Output is correct
12 Correct 2 ms 5344 KB Output is correct
13 Correct 5 ms 5344 KB Output is correct
14 Correct 7 ms 5344 KB Output is correct
15 Correct 4 ms 5344 KB Output is correct
16 Correct 7 ms 6268 KB Output is correct
17 Runtime error 29 ms 11280 KB SIGSEGV Segmentation fault
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4420 KB Output is correct
2 Correct 1 ms 4420 KB Output is correct
3 Correct 0 ms 4420 KB Output is correct
4 Correct 2 ms 4420 KB Output is correct
5 Correct 2 ms 4420 KB Output is correct
6 Correct 0 ms 4420 KB Output is correct
7 Correct 1 ms 4420 KB Output is correct
8 Correct 1 ms 4684 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5344 KB Output is correct
11 Correct 5 ms 5344 KB Output is correct
12 Correct 4 ms 5344 KB Output is correct
13 Correct 3 ms 5344 KB Output is correct
14 Correct 5 ms 5344 KB Output is correct
15 Correct 2 ms 5344 KB Output is correct
16 Correct 5 ms 6268 KB Output is correct
17 Runtime error 31 ms 11280 KB SIGSEGV Segmentation fault
18 Halted 0 ms 0 KB -