답안 #229702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229702 2020-05-06T00:31:05 Z Nightlight Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
192 ms 78312 KB
#include <queue>
#include <cstdio>
#include <cstring>
#include <set>
#define pii pair<int, int>
#define piii tuple<int, int, int>
#define mt make_tuple
#define push_back emplace_back
using namespace std;
 
int N, M;
int pos, mov, sta, fin;
vector<pii> adj[30005];
set<int> here[300005];
int dist[30005];

void BFS() {
  memset(dist, 0x3f3f3f3f, sizeof(dist));
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  pq.push(make_pair(0, sta));
  dist[sta] = 0;
  while(!pq.empty()) {
    int u = pq.top().second;
    int now = pq.top().first;
    pq.pop();
    if(dist[u] < now) continue;
    for(pii v : adj[u]) {
      if(dist[u] + v.second < dist[v.first]) {
        dist[v.first] = dist[u] + v.second;
        pq.push(make_pair(dist[v.first], v.first));
      }
    }
  }
  if(dist[fin] == 0x3f3f3f3f) puts("-1");
  else printf("%d\n", dist[fin]);
}
 
int main() {
  scanf("%d %d", &N, &M);
  scanf("%d %d", &pos, &mov);
  here[pos].insert(mov);
  sta = pos;
  scanf("%d %d", &pos, &mov);
  here[pos].insert(mov);
  fin = pos;
  for(int i = 2; i < M; i++) {
    scanf("%d %d", &pos, &mov);
    here[pos].insert(mov);
  }
  for(int i = 0; i <= N; i++) {
    if(i == fin) continue;
    for(int now : here[i]) {
      for(int nxt = i - now, p = 1; nxt >= 0; nxt -= now, p++) {
        adj[i].push_back(nxt, p);
        if(here[nxt].count(p)) break;
      }
      for(int nxt = i + now, p = 1; nxt <= N; nxt += now, p++) {
        adj[i].push_back(nxt, p);
        if(here[nxt].count(p)) break;
      }
    }
  }
  BFS();
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &N, &M);
   ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &pos, &mov);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &pos, &mov);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &pos, &mov);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 15232 KB Output is correct
2 Correct 13 ms 15232 KB Output is correct
3 Correct 14 ms 15232 KB Output is correct
4 Correct 13 ms 15232 KB Output is correct
5 Correct 15 ms 15232 KB Output is correct
6 Correct 13 ms 15232 KB Output is correct
7 Correct 13 ms 15232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 15232 KB Output is correct
2 Correct 13 ms 15232 KB Output is correct
3 Correct 13 ms 15232 KB Output is correct
4 Correct 13 ms 15232 KB Output is correct
5 Correct 13 ms 15232 KB Output is correct
6 Correct 13 ms 15232 KB Output is correct
7 Correct 13 ms 15232 KB Output is correct
8 Correct 13 ms 15232 KB Output is correct
9 Correct 13 ms 15232 KB Output is correct
10 Correct 13 ms 15232 KB Output is correct
11 Correct 14 ms 15360 KB Output is correct
12 Correct 13 ms 15232 KB Output is correct
13 Correct 13 ms 15232 KB Output is correct
14 Correct 14 ms 15360 KB Output is correct
15 Correct 14 ms 15360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 15232 KB Output is correct
2 Correct 13 ms 15232 KB Output is correct
3 Correct 13 ms 15232 KB Output is correct
4 Correct 13 ms 15232 KB Output is correct
5 Correct 13 ms 15232 KB Output is correct
6 Correct 13 ms 15232 KB Output is correct
7 Correct 13 ms 15232 KB Output is correct
8 Correct 13 ms 15192 KB Output is correct
9 Correct 13 ms 15232 KB Output is correct
10 Correct 13 ms 15232 KB Output is correct
11 Correct 14 ms 15360 KB Output is correct
12 Correct 13 ms 15232 KB Output is correct
13 Correct 13 ms 15232 KB Output is correct
14 Correct 14 ms 15360 KB Output is correct
15 Correct 14 ms 15360 KB Output is correct
16 Correct 13 ms 15360 KB Output is correct
17 Correct 15 ms 15488 KB Output is correct
18 Correct 13 ms 15360 KB Output is correct
19 Correct 13 ms 15232 KB Output is correct
20 Correct 14 ms 15360 KB Output is correct
21 Correct 13 ms 15360 KB Output is correct
22 Correct 14 ms 15360 KB Output is correct
23 Correct 14 ms 15360 KB Output is correct
24 Correct 15 ms 15488 KB Output is correct
25 Correct 15 ms 15360 KB Output is correct
26 Correct 14 ms 15360 KB Output is correct
27 Correct 14 ms 15360 KB Output is correct
28 Correct 15 ms 15616 KB Output is correct
29 Correct 16 ms 16000 KB Output is correct
30 Correct 16 ms 15616 KB Output is correct
31 Correct 16 ms 15616 KB Output is correct
32 Correct 14 ms 15488 KB Output is correct
33 Correct 19 ms 16768 KB Output is correct
34 Correct 18 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 15232 KB Output is correct
2 Correct 13 ms 15232 KB Output is correct
3 Correct 13 ms 15232 KB Output is correct
4 Correct 13 ms 15232 KB Output is correct
5 Correct 13 ms 15232 KB Output is correct
6 Correct 13 ms 15232 KB Output is correct
7 Correct 13 ms 15232 KB Output is correct
8 Correct 13 ms 15232 KB Output is correct
9 Correct 13 ms 15232 KB Output is correct
10 Correct 13 ms 15232 KB Output is correct
11 Correct 14 ms 15360 KB Output is correct
12 Correct 16 ms 15232 KB Output is correct
13 Correct 14 ms 15232 KB Output is correct
14 Correct 14 ms 15360 KB Output is correct
15 Correct 14 ms 15360 KB Output is correct
16 Correct 13 ms 15360 KB Output is correct
17 Correct 15 ms 15488 KB Output is correct
18 Correct 14 ms 15360 KB Output is correct
19 Correct 13 ms 15360 KB Output is correct
20 Correct 14 ms 15360 KB Output is correct
21 Correct 13 ms 15232 KB Output is correct
22 Correct 14 ms 15360 KB Output is correct
23 Correct 14 ms 15360 KB Output is correct
24 Correct 17 ms 15488 KB Output is correct
25 Correct 15 ms 15360 KB Output is correct
26 Correct 14 ms 15360 KB Output is correct
27 Correct 14 ms 15352 KB Output is correct
28 Correct 14 ms 15616 KB Output is correct
29 Correct 16 ms 16128 KB Output is correct
30 Correct 14 ms 15488 KB Output is correct
31 Correct 15 ms 15616 KB Output is correct
32 Correct 14 ms 15488 KB Output is correct
33 Correct 18 ms 16768 KB Output is correct
34 Correct 18 ms 16768 KB Output is correct
35 Correct 31 ms 17664 KB Output is correct
36 Correct 16 ms 15616 KB Output is correct
37 Correct 31 ms 18424 KB Output is correct
38 Correct 36 ms 18688 KB Output is correct
39 Correct 36 ms 18816 KB Output is correct
40 Correct 36 ms 18680 KB Output is correct
41 Correct 36 ms 18680 KB Output is correct
42 Correct 19 ms 15488 KB Output is correct
43 Correct 19 ms 15488 KB Output is correct
44 Correct 19 ms 15616 KB Output is correct
45 Correct 38 ms 21240 KB Output is correct
46 Correct 41 ms 21496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 15232 KB Output is correct
2 Correct 13 ms 15232 KB Output is correct
3 Correct 14 ms 15232 KB Output is correct
4 Correct 13 ms 15232 KB Output is correct
5 Correct 13 ms 15232 KB Output is correct
6 Correct 13 ms 15232 KB Output is correct
7 Correct 13 ms 15232 KB Output is correct
8 Correct 13 ms 15232 KB Output is correct
9 Correct 13 ms 15360 KB Output is correct
10 Correct 13 ms 15232 KB Output is correct
11 Correct 14 ms 15360 KB Output is correct
12 Correct 13 ms 15232 KB Output is correct
13 Correct 13 ms 15232 KB Output is correct
14 Correct 14 ms 15360 KB Output is correct
15 Correct 13 ms 15360 KB Output is correct
16 Correct 13 ms 15360 KB Output is correct
17 Correct 14 ms 15488 KB Output is correct
18 Correct 16 ms 15488 KB Output is correct
19 Correct 13 ms 15232 KB Output is correct
20 Correct 14 ms 15360 KB Output is correct
21 Correct 13 ms 15232 KB Output is correct
22 Correct 14 ms 15360 KB Output is correct
23 Correct 14 ms 15360 KB Output is correct
24 Correct 14 ms 15488 KB Output is correct
25 Correct 14 ms 15360 KB Output is correct
26 Correct 14 ms 15360 KB Output is correct
27 Correct 14 ms 15360 KB Output is correct
28 Correct 14 ms 15488 KB Output is correct
29 Correct 16 ms 16024 KB Output is correct
30 Correct 14 ms 15488 KB Output is correct
31 Correct 15 ms 15744 KB Output is correct
32 Correct 14 ms 15488 KB Output is correct
33 Correct 18 ms 16768 KB Output is correct
34 Correct 18 ms 16768 KB Output is correct
35 Correct 31 ms 17664 KB Output is correct
36 Correct 16 ms 15616 KB Output is correct
37 Correct 31 ms 18432 KB Output is correct
38 Correct 36 ms 18680 KB Output is correct
39 Correct 38 ms 18808 KB Output is correct
40 Correct 37 ms 18816 KB Output is correct
41 Correct 36 ms 18688 KB Output is correct
42 Correct 18 ms 15488 KB Output is correct
43 Correct 19 ms 15488 KB Output is correct
44 Correct 18 ms 15616 KB Output is correct
45 Correct 38 ms 21376 KB Output is correct
46 Correct 38 ms 21240 KB Output is correct
47 Correct 63 ms 25464 KB Output is correct
48 Correct 31 ms 18816 KB Output is correct
49 Correct 29 ms 17920 KB Output is correct
50 Correct 24 ms 17536 KB Output is correct
51 Correct 58 ms 21236 KB Output is correct
52 Correct 56 ms 21364 KB Output is correct
53 Correct 30 ms 17788 KB Output is correct
54 Correct 15 ms 15616 KB Output is correct
55 Correct 15 ms 15868 KB Output is correct
56 Correct 28 ms 17792 KB Output is correct
57 Correct 123 ms 69100 KB Output is correct
58 Correct 22 ms 16120 KB Output is correct
59 Correct 22 ms 16892 KB Output is correct
60 Correct 24 ms 17280 KB Output is correct
61 Correct 23 ms 16552 KB Output is correct
62 Correct 40 ms 21752 KB Output is correct
63 Correct 82 ms 38640 KB Output is correct
64 Correct 90 ms 42228 KB Output is correct
65 Correct 113 ms 51568 KB Output is correct
66 Correct 192 ms 78312 KB Output is correct
67 Correct 188 ms 78312 KB Output is correct