Submission #1028651

# Submission time Handle Problem Language Result Execution time Memory
1028651 2024-07-20T06:42:12 Z vjudge1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
339 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;
  
  vector<vector<int> > dist(n, vector<int> (m, 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();
      if(f == b[1])
	{
	  cout << dist[f][s] << endl;
	  exit(0);
	}
      // 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});
	}
    }

  cout << -1 << endl;
  return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:25:7: warning: unused variable 'cnt' [-Wunused-variable]
   25 |   int cnt[n] = {};
      |       ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 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 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 412 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 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1112 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 3 ms 5468 KB Output is correct
18 Correct 3 ms 7152 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 83 ms 16324 KB Output is correct
21 Correct 1 ms 2136 KB Output is correct
22 Correct 2 ms 5468 KB Output is correct
23 Correct 3 ms 6492 KB Output is correct
24 Correct 6 ms 14684 KB Output is correct
25 Correct 8 ms 16220 KB Output is correct
26 Correct 6 ms 16220 KB Output is correct
27 Correct 7 ms 16252 KB Output is correct
28 Correct 11 ms 16220 KB Output is correct
29 Correct 4 ms 6432 KB Output is correct
30 Correct 1 ms 1884 KB Output is correct
31 Correct 6 ms 4956 KB Output is correct
32 Correct 4 ms 4384 KB Output is correct
33 Correct 18 ms 16220 KB Output is correct
34 Correct 14 ms 16292 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 1 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 1 ms 1116 KB Output is correct
13 Correct 2 ms 1276 KB Output is correct
14 Correct 1 ms 1112 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 3 ms 5672 KB Output is correct
18 Correct 3 ms 7260 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 93 ms 16328 KB Output is correct
21 Correct 1 ms 2140 KB Output is correct
22 Correct 2 ms 5540 KB Output is correct
23 Correct 3 ms 6492 KB Output is correct
24 Correct 6 ms 14424 KB Output is correct
25 Correct 6 ms 16216 KB Output is correct
26 Correct 7 ms 16220 KB Output is correct
27 Correct 7 ms 16220 KB Output is correct
28 Correct 7 ms 16184 KB Output is correct
29 Correct 6 ms 6236 KB Output is correct
30 Correct 1 ms 1884 KB Output is correct
31 Correct 4 ms 4956 KB Output is correct
32 Correct 4 ms 4188 KB Output is correct
33 Correct 12 ms 16216 KB Output is correct
34 Correct 10 ms 16288 KB Output is correct
35 Correct 68 ms 145444 KB Output is correct
36 Correct 8 ms 20568 KB Output is correct
37 Correct 59 ms 147796 KB Output is correct
38 Correct 143 ms 235564 KB Output is correct
39 Correct 95 ms 235712 KB Output is correct
40 Correct 102 ms 235856 KB Output is correct
41 Correct 95 ms 235648 KB Output is correct
42 Correct 96 ms 235860 KB Output is correct
43 Correct 104 ms 235792 KB Output is correct
44 Correct 339 ms 236116 KB Output is correct
45 Correct 142 ms 235872 KB Output is correct
46 Correct 123 ms 235860 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 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 1 ms 1116 KB Output is correct
13 Correct 1 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 3 ms 5684 KB Output is correct
18 Correct 4 ms 7260 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 93 ms 16332 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 6 ms 14564 KB Output is correct
25 Correct 7 ms 16220 KB Output is correct
26 Correct 6 ms 16196 KB Output is correct
27 Correct 7 ms 16216 KB Output is correct
28 Correct 8 ms 16220 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 5208 KB Output is correct
32 Correct 5 ms 4188 KB Output is correct
33 Correct 15 ms 16220 KB Output is correct
34 Correct 15 ms 16220 KB Output is correct
35 Correct 77 ms 145356 KB Output is correct
36 Correct 11 ms 20824 KB Output is correct
37 Correct 61 ms 147792 KB Output is correct
38 Correct 98 ms 235408 KB Output is correct
39 Correct 104 ms 235860 KB Output is correct
40 Correct 92 ms 235856 KB Output is correct
41 Correct 94 ms 235600 KB Output is correct
42 Correct 94 ms 235856 KB Output is correct
43 Correct 96 ms 235692 KB Output is correct
44 Correct 318 ms 236112 KB Output is correct
45 Correct 142 ms 235860 KB Output is correct
46 Correct 123 ms 236112 KB Output is correct
47 Runtime error 130 ms 262144 KB Execution killed with signal 9
48 Halted 0 ms 0 KB -