답안 #961861

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961861 2024-04-12T15:01:45 Z vjudge1 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
310 ms 262144 KB
#include<bits/stdc++.h>

using namespace std;

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

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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 131932 KB Output is correct
2 Correct 31 ms 132224 KB Output is correct
3 Correct 30 ms 131924 KB Output is correct
4 Correct 29 ms 131972 KB Output is correct
5 Correct 29 ms 131928 KB Output is correct
6 Correct 30 ms 131808 KB Output is correct
7 Correct 28 ms 131932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 132008 KB Output is correct
2 Correct 31 ms 131924 KB Output is correct
3 Correct 29 ms 131804 KB Output is correct
4 Correct 29 ms 132180 KB Output is correct
5 Correct 30 ms 132028 KB Output is correct
6 Correct 30 ms 131928 KB Output is correct
7 Correct 28 ms 131932 KB Output is correct
8 Correct 29 ms 132104 KB Output is correct
9 Correct 30 ms 132188 KB Output is correct
10 Correct 37 ms 133320 KB Output is correct
11 Correct 44 ms 137456 KB Output is correct
12 Correct 34 ms 135772 KB Output is correct
13 Correct 34 ms 136020 KB Output is correct
14 Correct 39 ms 137188 KB Output is correct
15 Correct 38 ms 137120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 131884 KB Output is correct
2 Correct 29 ms 131968 KB Output is correct
3 Correct 28 ms 132036 KB Output is correct
4 Correct 28 ms 131928 KB Output is correct
5 Correct 29 ms 131928 KB Output is correct
6 Correct 29 ms 131932 KB Output is correct
7 Correct 28 ms 131808 KB Output is correct
8 Correct 30 ms 131932 KB Output is correct
9 Correct 31 ms 132176 KB Output is correct
10 Correct 37 ms 133204 KB Output is correct
11 Correct 43 ms 137556 KB Output is correct
12 Correct 36 ms 135764 KB Output is correct
13 Correct 36 ms 136028 KB Output is correct
14 Correct 39 ms 137052 KB Output is correct
15 Correct 37 ms 137040 KB Output is correct
16 Correct 37 ms 134844 KB Output is correct
17 Correct 49 ms 140636 KB Output is correct
18 Correct 52 ms 143696 KB Output is correct
19 Correct 50 ms 143452 KB Output is correct
20 Correct 65 ms 150300 KB Output is correct
21 Correct 37 ms 136808 KB Output is correct
22 Correct 51 ms 143188 KB Output is correct
23 Correct 51 ms 142880 KB Output is correct
24 Correct 59 ms 147060 KB Output is correct
25 Correct 59 ms 148052 KB Output is correct
26 Correct 53 ms 145488 KB Output is correct
27 Correct 54 ms 145244 KB Output is correct
28 Correct 75 ms 150100 KB Output is correct
29 Correct 63 ms 142928 KB Output is correct
30 Correct 58 ms 141624 KB Output is correct
31 Correct 58 ms 143048 KB Output is correct
32 Correct 57 ms 142532 KB Output is correct
33 Correct 81 ms 146000 KB Output is correct
34 Correct 75 ms 145996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 131928 KB Output is correct
2 Correct 30 ms 132000 KB Output is correct
3 Correct 30 ms 131932 KB Output is correct
4 Correct 29 ms 132060 KB Output is correct
5 Correct 30 ms 131812 KB Output is correct
6 Correct 29 ms 131928 KB Output is correct
7 Correct 28 ms 131932 KB Output is correct
8 Correct 30 ms 131932 KB Output is correct
9 Correct 29 ms 132064 KB Output is correct
10 Correct 31 ms 133204 KB Output is correct
11 Correct 39 ms 137560 KB Output is correct
12 Correct 34 ms 135888 KB Output is correct
13 Correct 33 ms 136028 KB Output is correct
14 Correct 40 ms 137184 KB Output is correct
15 Correct 38 ms 137180 KB Output is correct
16 Correct 34 ms 134748 KB Output is correct
17 Correct 48 ms 140628 KB Output is correct
18 Correct 50 ms 143664 KB Output is correct
19 Correct 50 ms 143440 KB Output is correct
20 Correct 64 ms 149940 KB Output is correct
21 Correct 38 ms 136788 KB Output is correct
22 Correct 49 ms 142972 KB Output is correct
23 Correct 51 ms 142764 KB Output is correct
24 Correct 65 ms 147476 KB Output is correct
25 Correct 64 ms 148052 KB Output is correct
26 Correct 55 ms 145496 KB Output is correct
27 Correct 58 ms 145204 KB Output is correct
28 Correct 74 ms 150300 KB Output is correct
29 Correct 63 ms 143036 KB Output is correct
30 Correct 53 ms 141656 KB Output is correct
31 Correct 57 ms 142936 KB Output is correct
32 Correct 57 ms 142396 KB Output is correct
33 Correct 77 ms 146060 KB Output is correct
34 Correct 86 ms 146004 KB Output is correct
35 Correct 219 ms 208716 KB Output is correct
36 Correct 70 ms 150100 KB Output is correct
37 Correct 188 ms 193400 KB Output is correct
38 Correct 236 ms 224892 KB Output is correct
39 Correct 255 ms 224596 KB Output is correct
40 Correct 310 ms 224936 KB Output is correct
41 Correct 246 ms 224660 KB Output is correct
42 Correct 116 ms 195804 KB Output is correct
43 Correct 123 ms 195648 KB Output is correct
44 Correct 139 ms 201644 KB Output is correct
45 Correct 221 ms 216216 KB Output is correct
46 Correct 220 ms 216152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 131932 KB Output is correct
2 Correct 29 ms 132000 KB Output is correct
3 Correct 28 ms 131928 KB Output is correct
4 Correct 30 ms 131932 KB Output is correct
5 Correct 29 ms 131928 KB Output is correct
6 Correct 31 ms 132188 KB Output is correct
7 Correct 32 ms 131928 KB Output is correct
8 Correct 31 ms 131932 KB Output is correct
9 Correct 32 ms 132240 KB Output is correct
10 Correct 33 ms 133324 KB Output is correct
11 Correct 39 ms 137432 KB Output is correct
12 Correct 33 ms 135772 KB Output is correct
13 Correct 37 ms 136532 KB Output is correct
14 Correct 37 ms 137172 KB Output is correct
15 Correct 38 ms 137176 KB Output is correct
16 Correct 34 ms 134964 KB Output is correct
17 Correct 51 ms 140628 KB Output is correct
18 Correct 54 ms 143656 KB Output is correct
19 Correct 51 ms 143444 KB Output is correct
20 Correct 64 ms 150036 KB Output is correct
21 Correct 37 ms 136788 KB Output is correct
22 Correct 49 ms 142860 KB Output is correct
23 Correct 59 ms 142740 KB Output is correct
24 Correct 60 ms 147284 KB Output is correct
25 Correct 59 ms 148308 KB Output is correct
26 Correct 55 ms 145500 KB Output is correct
27 Correct 60 ms 145200 KB Output is correct
28 Correct 70 ms 150352 KB Output is correct
29 Correct 62 ms 143176 KB Output is correct
30 Correct 60 ms 141916 KB Output is correct
31 Correct 58 ms 143056 KB Output is correct
32 Correct 55 ms 142424 KB Output is correct
33 Correct 73 ms 146000 KB Output is correct
34 Correct 76 ms 145852 KB Output is correct
35 Correct 208 ms 208784 KB Output is correct
36 Correct 67 ms 150100 KB Output is correct
37 Correct 200 ms 193468 KB Output is correct
38 Correct 266 ms 224940 KB Output is correct
39 Correct 260 ms 224524 KB Output is correct
40 Correct 260 ms 225060 KB Output is correct
41 Correct 259 ms 224624 KB Output is correct
42 Correct 117 ms 196080 KB Output is correct
43 Correct 128 ms 195640 KB Output is correct
44 Correct 137 ms 201696 KB Output is correct
45 Correct 219 ms 216308 KB Output is correct
46 Correct 215 ms 216148 KB Output is correct
47 Runtime error 301 ms 262144 KB Execution killed with signal 9
48 Halted 0 ms 0 KB -