Submission #961863

# Submission time Handle Problem Language Result Execution time Memory
961863 2024-04-12T15:04:56 Z vjudge1 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
739 ms 243780 KB
#include<bits/stdc++.h>

using namespace std;

#ifdef sus
const int N=100, S=3;
#else
const int N=3e4+10, S=80;
#endif
int n, m, b[N], p[N], heavy[N];
int f[N][S+1];
vector<pair<pair<int, int>, int>> g[N][S+1];

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cin >> n >> m;
   for (int i=1; i<=m; ++i) cin >> b[i] >> p[i], heavy[i]=p[i]>=S, ++b[i];
   for (int i=1; i<=m; ++i) if (heavy[i]){
      for (int l=b[i]-p[i], r=b[i]+p[i], cnt=1; l>=1 || r<=n; l-=p[i], r+=p[i], ++cnt){
         if (l>=1) g[b[i]][S].push_back({{l, S}, cnt});
         if (r<=n) g[b[i]][S].push_back({{r, S}, cnt});
      }
      for (int j=1; j<S; ++j) g[b[i]][j].push_back({{b[i], S}, 0});
   }
   for (int i=1; i<=m; ++i) if (!heavy[i]){
      for (int j=1; j<=S; ++j) if (j!=p[i]) g[b[i]][j].push_back({{b[i], p[i]}, 0});
   }
   for (int i=1; i<=n; ++i) for (int j=1; j<S; ++j){
      if (i-j>=1) g[i][j].push_back({{i-j, j}, 1});
      if (i+j<=n) g[i][j].push_back({{i+j, j}, 1});
   }
   priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;
   memset(f, 0x3f, sizeof f);
   pq.push({f[b[1]][min(S, p[1])]=0, {b[1], min(S, p[1])}});
   while (pq.size()){
      auto u=pq.top().second;
      int d=pq.top().first;
      pq.pop();
      if (f[u.first][u.second]!=d) continue;
      for (auto &e:g[u.first][u.second]){
         auto v=e.first; int w=e.second;
         if (f[v.first][v.second]>d+w) pq.emplace(f[v.first][v.second]=d+w, v);
      }
   }
   int ans=*min_element(f[b[2]]+1, f[b[2]]+S+1);
   if (ans>1e9) ans=-1;
   cout << ans << '\n';
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 66816 KB Output is correct
2 Correct 18 ms 66908 KB Output is correct
3 Correct 17 ms 66908 KB Output is correct
4 Correct 15 ms 66976 KB Output is correct
5 Correct 16 ms 66908 KB Output is correct
6 Correct 16 ms 66956 KB Output is correct
7 Correct 15 ms 66904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 66908 KB Output is correct
2 Correct 15 ms 66908 KB Output is correct
3 Correct 15 ms 66908 KB Output is correct
4 Correct 15 ms 66904 KB Output is correct
5 Correct 15 ms 67160 KB Output is correct
6 Correct 15 ms 66904 KB Output is correct
7 Correct 17 ms 67072 KB Output is correct
8 Correct 16 ms 67124 KB Output is correct
9 Correct 16 ms 67164 KB Output is correct
10 Correct 17 ms 67848 KB Output is correct
11 Correct 24 ms 69980 KB Output is correct
12 Correct 18 ms 69212 KB Output is correct
13 Correct 18 ms 69212 KB Output is correct
14 Correct 21 ms 69908 KB Output is correct
15 Correct 24 ms 69720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 66908 KB Output is correct
2 Correct 17 ms 67068 KB Output is correct
3 Correct 15 ms 66908 KB Output is correct
4 Correct 15 ms 66908 KB Output is correct
5 Correct 16 ms 66824 KB Output is correct
6 Correct 16 ms 66908 KB Output is correct
7 Correct 15 ms 66820 KB Output is correct
8 Correct 15 ms 66940 KB Output is correct
9 Correct 15 ms 67164 KB Output is correct
10 Correct 17 ms 68004 KB Output is correct
11 Correct 21 ms 69980 KB Output is correct
12 Correct 18 ms 69212 KB Output is correct
13 Correct 18 ms 69396 KB Output is correct
14 Correct 21 ms 69752 KB Output is correct
15 Correct 20 ms 69724 KB Output is correct
16 Correct 18 ms 68696 KB Output is correct
17 Correct 27 ms 71772 KB Output is correct
18 Correct 27 ms 73304 KB Output is correct
19 Correct 32 ms 73132 KB Output is correct
20 Correct 35 ms 76632 KB Output is correct
21 Correct 24 ms 69724 KB Output is correct
22 Correct 26 ms 72912 KB Output is correct
23 Correct 34 ms 72868 KB Output is correct
24 Correct 33 ms 75124 KB Output is correct
25 Correct 32 ms 75604 KB Output is correct
26 Correct 30 ms 74064 KB Output is correct
27 Correct 29 ms 73912 KB Output is correct
28 Correct 37 ms 76888 KB Output is correct
29 Correct 37 ms 72796 KB Output is correct
30 Correct 28 ms 72028 KB Output is correct
31 Correct 38 ms 72872 KB Output is correct
32 Correct 33 ms 72540 KB Output is correct
33 Correct 47 ms 74412 KB Output is correct
34 Correct 46 ms 74584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 66904 KB Output is correct
2 Correct 15 ms 67068 KB Output is correct
3 Correct 15 ms 66948 KB Output is correct
4 Correct 15 ms 66908 KB Output is correct
5 Correct 15 ms 66916 KB Output is correct
6 Correct 15 ms 66904 KB Output is correct
7 Correct 15 ms 66908 KB Output is correct
8 Correct 15 ms 66936 KB Output is correct
9 Correct 16 ms 67160 KB Output is correct
10 Correct 16 ms 67856 KB Output is correct
11 Correct 21 ms 69976 KB Output is correct
12 Correct 19 ms 69188 KB Output is correct
13 Correct 18 ms 69212 KB Output is correct
14 Correct 21 ms 69724 KB Output is correct
15 Correct 23 ms 69724 KB Output is correct
16 Correct 20 ms 68760 KB Output is correct
17 Correct 25 ms 71768 KB Output is correct
18 Correct 27 ms 73128 KB Output is correct
19 Correct 27 ms 73052 KB Output is correct
20 Correct 34 ms 76636 KB Output is correct
21 Correct 20 ms 69688 KB Output is correct
22 Correct 25 ms 72796 KB Output is correct
23 Correct 26 ms 72940 KB Output is correct
24 Correct 36 ms 75096 KB Output is correct
25 Correct 34 ms 75936 KB Output is correct
26 Correct 29 ms 74076 KB Output is correct
27 Correct 29 ms 74132 KB Output is correct
28 Correct 38 ms 76868 KB Output is correct
29 Correct 36 ms 72796 KB Output is correct
30 Correct 29 ms 72256 KB Output is correct
31 Correct 38 ms 72788 KB Output is correct
32 Correct 35 ms 72644 KB Output is correct
33 Correct 46 ms 74580 KB Output is correct
34 Correct 47 ms 74428 KB Output is correct
35 Correct 103 ms 108368 KB Output is correct
36 Correct 38 ms 76752 KB Output is correct
37 Correct 131 ms 100960 KB Output is correct
38 Correct 139 ms 117420 KB Output is correct
39 Correct 138 ms 117100 KB Output is correct
40 Correct 140 ms 117584 KB Output is correct
41 Correct 143 ms 117616 KB Output is correct
42 Correct 64 ms 100868 KB Output is correct
43 Correct 64 ms 100892 KB Output is correct
44 Correct 78 ms 104304 KB Output is correct
45 Correct 124 ms 114912 KB Output is correct
46 Correct 120 ms 115100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 67072 KB Output is correct
2 Correct 18 ms 66908 KB Output is correct
3 Correct 17 ms 66908 KB Output is correct
4 Correct 17 ms 66908 KB Output is correct
5 Correct 16 ms 66908 KB Output is correct
6 Correct 15 ms 67076 KB Output is correct
7 Correct 16 ms 67024 KB Output is correct
8 Correct 15 ms 66908 KB Output is correct
9 Correct 15 ms 66988 KB Output is correct
10 Correct 17 ms 67676 KB Output is correct
11 Correct 21 ms 70232 KB Output is correct
12 Correct 18 ms 69064 KB Output is correct
13 Correct 18 ms 69196 KB Output is correct
14 Correct 20 ms 69724 KB Output is correct
15 Correct 20 ms 69724 KB Output is correct
16 Correct 18 ms 68700 KB Output is correct
17 Correct 27 ms 71772 KB Output is correct
18 Correct 27 ms 73300 KB Output is correct
19 Correct 26 ms 73048 KB Output is correct
20 Correct 43 ms 76624 KB Output is correct
21 Correct 22 ms 69720 KB Output is correct
22 Correct 26 ms 72784 KB Output is correct
23 Correct 27 ms 72796 KB Output is correct
24 Correct 33 ms 75092 KB Output is correct
25 Correct 34 ms 75460 KB Output is correct
26 Correct 29 ms 74288 KB Output is correct
27 Correct 29 ms 74076 KB Output is correct
28 Correct 41 ms 76704 KB Output is correct
29 Correct 42 ms 72796 KB Output is correct
30 Correct 29 ms 72280 KB Output is correct
31 Correct 32 ms 72792 KB Output is correct
32 Correct 31 ms 72540 KB Output is correct
33 Correct 47 ms 74588 KB Output is correct
34 Correct 53 ms 74588 KB Output is correct
35 Correct 106 ms 108372 KB Output is correct
36 Correct 35 ms 76892 KB Output is correct
37 Correct 118 ms 100732 KB Output is correct
38 Correct 134 ms 117240 KB Output is correct
39 Correct 146 ms 117064 KB Output is correct
40 Correct 141 ms 117588 KB Output is correct
41 Correct 144 ms 117332 KB Output is correct
42 Correct 65 ms 100868 KB Output is correct
43 Correct 70 ms 101124 KB Output is correct
44 Correct 81 ms 104408 KB Output is correct
45 Correct 116 ms 114700 KB Output is correct
46 Correct 116 ms 115016 KB Output is correct
47 Correct 344 ms 146448 KB Output is correct
48 Correct 213 ms 168244 KB Output is correct
49 Correct 230 ms 172292 KB Output is correct
50 Correct 211 ms 167508 KB Output is correct
51 Correct 351 ms 200244 KB Output is correct
52 Correct 368 ms 200916 KB Output is correct
53 Correct 299 ms 197492 KB Output is correct
54 Correct 155 ms 141136 KB Output is correct
55 Correct 160 ms 141136 KB Output is correct
56 Correct 311 ms 216660 KB Output is correct
57 Correct 348 ms 146752 KB Output is correct
58 Correct 225 ms 170136 KB Output is correct
59 Correct 218 ms 170220 KB Output is correct
60 Correct 249 ms 171488 KB Output is correct
61 Correct 237 ms 172096 KB Output is correct
62 Correct 404 ms 220236 KB Output is correct
63 Correct 335 ms 216496 KB Output is correct
64 Correct 309 ms 219736 KB Output is correct
65 Correct 353 ms 238188 KB Output is correct
66 Correct 739 ms 243780 KB Output is correct
67 Correct 739 ms 242444 KB Output is correct