Submission #229614

# Submission time Handle Problem Language Result Execution time Memory
229614 2020-05-05T10:41:59 Z Nightlight Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 45176 KB
#include <queue>
#include <cstdio>
#include <tuple>
#include <cstring>
#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;
pii A[30005];
int dist[30005][180];
int vis[30005][180];
vector<pii> adj[30005];
vector<int> dog[30005];

void BFS() {
  priority_queue<piii> pq;
  memset(dist, 0x3f3f3f3f, sizeof(dist));
  memset(vis, 0x3f3f3f3f, sizeof(vis));
  pq.push(make_tuple(0, A[0].first, 0));
  dist[A[0].first][0] = 0;
  int u, mov; int trav;
  while(!pq.empty()) {
    tie(trav, u, mov) = pq.top();
    pq.pop();
    if(dist[u][mov] < trav || vis[u][mov] <= trav) continue;
    if(mov != 0) {
      if(u - mov >= 0 && trav + 1 < dist[u - mov][mov]) {
        dist[u - mov][mov] = trav + 1;
        pq.push(make_tuple(trav + 1, u - mov, mov));
      }
      if(u + mov <= N && trav + 1 < dist[u + mov][mov]) {
        dist[u + mov][mov] = trav + 1;
        pq.push(make_tuple(trav + 1, u + mov, mov));
      }
      if(dist[u][0] > trav) {
        dist[u][0] = trav;
        pq.push(make_tuple(trav, u, 0));
      }
    }else {
      int v, w;
      for(pii now : adj[u]) {
        v = now.first, w = now.second + trav;
        if(w < dist[v][0]) {
          dist[v][0] = w;
          pq.push(make_tuple(w, v, 0));
        }
      }
      for(int v : dog[u]) {
        if(trav < dist[u][v]) {
          dist[u][v] = trav;
          pq.push(make_tuple(trav, u, v));
        }
      }
    }
    vis[u][mov] = trav;
  }
  if(dist[A[1].first][0] == 0x3f3f3f3f) puts("-1");
  else printf("%d\n", dist[A[1].first][0]);
}

int main() {
//  freopen("out.txt", "w", stdout);
  scanf("%d %d", &N, &M);
  int pos, mov;
  for(int i = 0; i < M; i++) {
    scanf("%d %d", &pos, &mov);
    A[i] = make_pair(pos, mov);
    if(mov * mov > N) {
      for(int i = pos - mov, j = 1; i >= 0; i -= mov, j++) {
        adj[pos].push_back(i, j);
      }
      for(int i = pos + mov, j = 1; i <= N; i += mov, j++) {
        adj[pos].push_back(i, j);
      }
    }else {
      dog[pos].push_back(mov);
    }
  }
  BFS();
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:66: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:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &pos, &mov);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 44032 KB Output is correct
2 Correct 27 ms 44032 KB Output is correct
3 Correct 27 ms 44032 KB Output is correct
4 Correct 27 ms 44032 KB Output is correct
5 Correct 27 ms 44024 KB Output is correct
6 Correct 27 ms 44024 KB Output is correct
7 Correct 27 ms 44032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 44032 KB Output is correct
2 Correct 26 ms 44032 KB Output is correct
3 Correct 27 ms 44032 KB Output is correct
4 Correct 27 ms 44032 KB Output is correct
5 Correct 29 ms 44032 KB Output is correct
6 Correct 28 ms 44032 KB Output is correct
7 Correct 27 ms 44032 KB Output is correct
8 Correct 27 ms 44024 KB Output is correct
9 Correct 26 ms 44032 KB Output is correct
10 Correct 27 ms 44024 KB Output is correct
11 Correct 34 ms 44080 KB Output is correct
12 Correct 26 ms 44032 KB Output is correct
13 Correct 28 ms 44032 KB Output is correct
14 Correct 27 ms 44032 KB Output is correct
15 Correct 27 ms 44160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 44032 KB Output is correct
2 Correct 25 ms 44032 KB Output is correct
3 Correct 26 ms 44032 KB Output is correct
4 Correct 27 ms 44032 KB Output is correct
5 Correct 27 ms 44288 KB Output is correct
6 Correct 27 ms 44032 KB Output is correct
7 Correct 27 ms 44032 KB Output is correct
8 Correct 27 ms 44032 KB Output is correct
9 Correct 27 ms 44024 KB Output is correct
10 Correct 28 ms 44024 KB Output is correct
11 Correct 28 ms 44032 KB Output is correct
12 Correct 26 ms 44032 KB Output is correct
13 Correct 27 ms 44024 KB Output is correct
14 Correct 28 ms 44032 KB Output is correct
15 Correct 27 ms 44160 KB Output is correct
16 Correct 27 ms 44024 KB Output is correct
17 Correct 128 ms 44160 KB Output is correct
18 Correct 27 ms 44032 KB Output is correct
19 Correct 27 ms 44032 KB Output is correct
20 Correct 28 ms 44160 KB Output is correct
21 Correct 27 ms 44032 KB Output is correct
22 Correct 27 ms 44032 KB Output is correct
23 Correct 36 ms 44032 KB Output is correct
24 Correct 105 ms 44160 KB Output is correct
25 Correct 36 ms 44160 KB Output is correct
26 Correct 29 ms 44156 KB Output is correct
27 Correct 27 ms 44024 KB Output is correct
28 Correct 30 ms 44160 KB Output is correct
29 Correct 30 ms 44032 KB Output is correct
30 Correct 29 ms 44032 KB Output is correct
31 Correct 28 ms 43988 KB Output is correct
32 Correct 29 ms 44280 KB Output is correct
33 Correct 32 ms 44544 KB Output is correct
34 Correct 47 ms 44536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 44032 KB Output is correct
2 Correct 27 ms 44032 KB Output is correct
3 Correct 26 ms 44024 KB Output is correct
4 Correct 28 ms 44032 KB Output is correct
5 Correct 27 ms 44032 KB Output is correct
6 Correct 27 ms 44032 KB Output is correct
7 Correct 27 ms 44032 KB Output is correct
8 Correct 26 ms 44032 KB Output is correct
9 Correct 26 ms 44024 KB Output is correct
10 Correct 27 ms 44024 KB Output is correct
11 Correct 29 ms 44160 KB Output is correct
12 Correct 26 ms 44032 KB Output is correct
13 Correct 27 ms 44032 KB Output is correct
14 Correct 27 ms 44032 KB Output is correct
15 Correct 27 ms 44032 KB Output is correct
16 Correct 27 ms 44024 KB Output is correct
17 Correct 126 ms 44160 KB Output is correct
18 Correct 27 ms 44032 KB Output is correct
19 Correct 26 ms 44032 KB Output is correct
20 Correct 28 ms 44160 KB Output is correct
21 Correct 26 ms 44028 KB Output is correct
22 Correct 26 ms 44032 KB Output is correct
23 Correct 36 ms 44032 KB Output is correct
24 Correct 108 ms 44160 KB Output is correct
25 Correct 34 ms 44160 KB Output is correct
26 Correct 29 ms 44160 KB Output is correct
27 Correct 28 ms 44160 KB Output is correct
28 Correct 29 ms 44160 KB Output is correct
29 Correct 30 ms 44032 KB Output is correct
30 Correct 28 ms 43996 KB Output is correct
31 Correct 29 ms 44032 KB Output is correct
32 Correct 28 ms 44160 KB Output is correct
33 Correct 34 ms 44544 KB Output is correct
34 Correct 48 ms 44536 KB Output is correct
35 Execution timed out 1061 ms 45132 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 44032 KB Output is correct
2 Correct 26 ms 44032 KB Output is correct
3 Correct 26 ms 44032 KB Output is correct
4 Correct 26 ms 44032 KB Output is correct
5 Correct 30 ms 44032 KB Output is correct
6 Correct 26 ms 44032 KB Output is correct
7 Correct 26 ms 44032 KB Output is correct
8 Correct 26 ms 44032 KB Output is correct
9 Correct 26 ms 44032 KB Output is correct
10 Correct 27 ms 44032 KB Output is correct
11 Correct 28 ms 44032 KB Output is correct
12 Correct 29 ms 44032 KB Output is correct
13 Correct 28 ms 44008 KB Output is correct
14 Correct 28 ms 44032 KB Output is correct
15 Correct 26 ms 44032 KB Output is correct
16 Correct 26 ms 44032 KB Output is correct
17 Correct 129 ms 44176 KB Output is correct
18 Correct 28 ms 44032 KB Output is correct
19 Correct 27 ms 44024 KB Output is correct
20 Correct 27 ms 44160 KB Output is correct
21 Correct 27 ms 44032 KB Output is correct
22 Correct 26 ms 44032 KB Output is correct
23 Correct 37 ms 44032 KB Output is correct
24 Correct 107 ms 44160 KB Output is correct
25 Correct 35 ms 44032 KB Output is correct
26 Correct 29 ms 44200 KB Output is correct
27 Correct 28 ms 44032 KB Output is correct
28 Correct 29 ms 44160 KB Output is correct
29 Correct 30 ms 44032 KB Output is correct
30 Correct 28 ms 44024 KB Output is correct
31 Correct 29 ms 44032 KB Output is correct
32 Correct 29 ms 44160 KB Output is correct
33 Correct 32 ms 44544 KB Output is correct
34 Correct 48 ms 44536 KB Output is correct
35 Execution timed out 1049 ms 45176 KB Time limit exceeded
36 Halted 0 ms 0 KB -