답안 #249202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
249202 2020-07-14T13:27:24 Z hunni10 Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 2092 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<math.h>
#include<string.h>
#include<queue>
#include<list>
#include<time.h>
#include<assert.h>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;

int n, m;

int b[30000];
int p[30000];
int shortest[30000];
bool visited[30000] = {0, };
bool inSorted[30000] = { 0, };
set<pii> sorted;

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d %d", b + i, p + i);
	}
	for (int i = 0; i < m; i++) {
		shortest[i] = 0x7FFFFFFF;
	}
	shortest[0] = 0;
	inSorted[0] = true;
	sorted.insert({ 0, 0 });
	while (true) {
		if (sorted.empty()) { printf("-1"); break; }
		pii now = *sorted.begin();
		if (now.second == 1) {
			printf("%d", now.first);
			break;
		}
		visited[now.second] = true;
		for (int i = 0; i < m; i++) {
			if (visited[i]) continue;
			if ((b[i] - b[now.second]) % p[now.second] == 0) {
				int times = (b[i] - b[now.second]) / p[now.second];
				if (times < 0) times = -times;
				times += now.first;
				if (times < shortest[i]) {
					if (inSorted) {
						sorted.erase({ shortest[i], i });
					}
					shortest[i] = times;
					sorted.insert({ shortest[i], i });
					inSorted[i] = true;
				}
			}
		}
		sorted.erase(sorted.begin());
	}
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", b + i, p + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 13 ms 384 KB Output is correct
14 Correct 16 ms 384 KB Output is correct
15 Correct 17 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 14 ms 512 KB Output is correct
14 Correct 16 ms 384 KB Output is correct
15 Correct 17 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 16 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 17 ms 476 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 18 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 19 ms 384 KB Output is correct
34 Correct 15 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 13 ms 496 KB Output is correct
14 Correct 19 ms 512 KB Output is correct
15 Correct 18 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 17 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 17 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 19 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 15 ms 384 KB Output is correct
34 Correct 16 ms 384 KB Output is correct
35 Execution timed out 1084 ms 2092 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 13 ms 384 KB Output is correct
14 Correct 16 ms 384 KB Output is correct
15 Correct 17 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 16 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 17 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 18 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 16 ms 384 KB Output is correct
34 Correct 16 ms 384 KB Output is correct
35 Execution timed out 1083 ms 2040 KB Time limit exceeded
36 Halted 0 ms 0 KB -