Submission #1028642

# Submission time Handle Problem Language Result Execution time Memory
1028642 2024-07-20T06:36:25 Z vjudge1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
918 ms 262144 KB
#include<bits/stdc++.h>

using namespace std;

const int inf = 1e9;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n, m;
  cin >> n >> m;
  
  int dist[n][m];
  for(int i = 0; i < n; i ++)
    for(int j = 0; j < m ; j++)
      dist[i][j] = inf;

  vector<int> L[n];
  int p[m], b[m];
  for(int i = 0; i < m; i ++)
    {
      cin >> b[i] >> p[i];
      L[b[i]].push_back(i);
    }

  int cnt[n] = {};
  deque<pair<int,int> > Q;
  Q.push_back({b[0], 0});
  dist[b[0]][0] = 0;
  while(Q.size())
    {
      int f = Q.front().first, s = Q.front().second;
      Q.pop_front();
      // cerr << f << ' ' << s << ' ' << dist[f][s] << endl;
      // if(cnt[f] <= 2000) {
	for(int res : L[f])
	  if(dist[f][s] < dist[f][res])
	    {
	      dist[f][res] = dist[f][s];
	      Q.push_front({f, res});
	    }
	// cnt[f]++;
      // }
      
      L[f].clear();
      
      if(f + p[s] < n && dist[f][s] + 1 < dist[f + p[s]][s])
	{
	  dist[f + p[s]][s] = dist[f][s] + 1;
	  Q.push_back({f + p[s], s});
	}

      if(f - p[s] >= 0 && dist[f][s] + 1 < dist[f - p[s]][s])
	{
	  dist[f - p[s]][s] = dist[f][s] + 1;
	  Q.push_back({f - p[s], s});
	}
    }

  if(dist[b[1]][1] == inf)
    cout << -1 << endl;
  else
    cout << dist[b[1]][1] << endl;
  return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:28:7: warning: unused variable 'cnt' [-Wunused-variable]
   28 |   int cnt[n] = {};
      |       ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 3 ms 1116 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 400 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 1264 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 3 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 5 ms 5468 KB Output is correct
18 Correct 7 ms 7168 KB Output is correct
19 Correct 3 ms 4700 KB Output is correct
20 Correct 111 ms 16256 KB Output is correct
21 Correct 2 ms 2140 KB Output is correct
22 Correct 5 ms 5468 KB Output is correct
23 Correct 4 ms 6488 KB Output is correct
24 Correct 16 ms 14500 KB Output is correct
25 Correct 12 ms 16220 KB Output is correct
26 Correct 45 ms 16216 KB Output is correct
27 Correct 44 ms 16220 KB Output is correct
28 Correct 11 ms 16220 KB Output is correct
29 Correct 5 ms 6232 KB Output is correct
30 Correct 2 ms 1884 KB Output is correct
31 Correct 4 ms 4956 KB Output is correct
32 Correct 3 ms 4188 KB Output is correct
33 Correct 14 ms 16156 KB Output is correct
34 Correct 16 ms 16224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 3 ms 1320 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 5 ms 5464 KB Output is correct
18 Correct 4 ms 7260 KB Output is correct
19 Correct 3 ms 4700 KB Output is correct
20 Correct 89 ms 16264 KB Output is correct
21 Correct 2 ms 2392 KB Output is correct
22 Correct 3 ms 5468 KB Output is correct
23 Correct 4 ms 6492 KB Output is correct
24 Correct 9 ms 14428 KB Output is correct
25 Correct 10 ms 16128 KB Output is correct
26 Correct 56 ms 16220 KB Output is correct
27 Correct 43 ms 16220 KB Output is correct
28 Correct 11 ms 16220 KB Output is correct
29 Correct 5 ms 6268 KB Output is correct
30 Correct 2 ms 1884 KB Output is correct
31 Correct 4 ms 4956 KB Output is correct
32 Correct 3 ms 4188 KB Output is correct
33 Correct 12 ms 16216 KB Output is correct
34 Correct 13 ms 16216 KB Output is correct
35 Correct 95 ms 145492 KB Output is correct
36 Correct 13 ms 20632 KB Output is correct
37 Correct 115 ms 148316 KB Output is correct
38 Correct 150 ms 235856 KB Output is correct
39 Correct 154 ms 236116 KB Output is correct
40 Correct 156 ms 236116 KB Output is correct
41 Correct 151 ms 236024 KB Output is correct
42 Correct 743 ms 236320 KB Output is correct
43 Correct 672 ms 236188 KB Output is correct
44 Correct 876 ms 236372 KB Output is correct
45 Correct 169 ms 236112 KB Output is correct
46 Correct 179 ms 236104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 3 ms 1116 KB Output is correct
14 Correct 2 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 4 ms 5588 KB Output is correct
18 Correct 4 ms 7260 KB Output is correct
19 Correct 3 ms 4700 KB Output is correct
20 Correct 91 ms 16252 KB Output is correct
21 Correct 1 ms 2140 KB Output is correct
22 Correct 3 ms 5468 KB Output is correct
23 Correct 4 ms 6492 KB Output is correct
24 Correct 10 ms 14428 KB Output is correct
25 Correct 14 ms 16024 KB Output is correct
26 Correct 44 ms 16216 KB Output is correct
27 Correct 44 ms 16220 KB Output is correct
28 Correct 13 ms 16216 KB Output is correct
29 Correct 6 ms 6236 KB Output is correct
30 Correct 2 ms 1884 KB Output is correct
31 Correct 4 ms 4956 KB Output is correct
32 Correct 3 ms 4188 KB Output is correct
33 Correct 16 ms 16220 KB Output is correct
34 Correct 13 ms 16108 KB Output is correct
35 Correct 96 ms 145608 KB Output is correct
36 Correct 14 ms 20572 KB Output is correct
37 Correct 106 ms 148144 KB Output is correct
38 Correct 137 ms 235684 KB Output is correct
39 Correct 153 ms 236256 KB Output is correct
40 Correct 148 ms 236140 KB Output is correct
41 Correct 146 ms 236032 KB Output is correct
42 Correct 759 ms 236624 KB Output is correct
43 Correct 693 ms 236372 KB Output is correct
44 Correct 918 ms 236440 KB Output is correct
45 Correct 210 ms 236112 KB Output is correct
46 Correct 160 ms 236112 KB Output is correct
47 Runtime error 126 ms 262144 KB Execution killed with signal 9
48 Halted 0 ms 0 KB -