답안 #45913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45913 2018-04-16T13:19:59 Z Talant Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 14900 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
#define int long long

using namespace std;

typedef long long ll;

const int inf = (int)1e15 + 7;
const int N = (int)2e5 + 7;

int n,m;
int b[N],p[N];
int d[N];

vector <int> vec[N];
vector <pair<int,int> > g[N];
priority_queue<pair<int,int> > q;

bool check (int l,int r,int x) {
      if (abs(r - l) % x == 0)
            return true;
      return false;
}
int f (int l,int r,int x) {
      return (abs(r - l) / x);
}
main () {
      cin >> n >> m;

      for (int i = 1; i <= m; i ++) {
            cin >> b[i] >> p[i];
            b[i] ++;
            vec[b[i]].pb(p[i]);
      }
      for (int i = 1; i <= n; i ++) {
            sort (vec[i].begin(),vec[i].end());
            vec[i].erase(unique(vec[i].begin(),vec[i].end()),vec[i].end());
      }

      for (int i = 1; i <= n; i ++)
            d[i] = inf;

      d[b[1]] = 0;
      q.push({0,b[1]});

      while (!q.empty()) {
            int v = q.top().sc,cur = -q.top().fr;
            q.pop();

            if (cur > d[v])
                  continue;
            if (b[2] == v) {
                  cout << d[v] << endl;
                  return 0;
            }
            for (auto to : vec[v]) {
                  for (int i = 1; to * i + v <= n; i ++) {
                        if (d[v] + i < d[to * i + v]) {
                              d[to * i + v] = d[v] + i;
                              q.push({-d[to * i + v],to * i + v});
                        }
                  }
                  for (int i = 1; to * i <= v; i ++) {
                        if (d[v] + i < d[v - to * i]) {
                              d[v - to * i] = d[v] + i;
                              q.push({-d[v - to * i],v - to * i});
                        }
                  }
            }
      }
      if (d[b[2]] == inf)
            puts("-1");
      else
            cout << d[b[2]] << endl;
}

Compilation message

skyscraper.cpp:33:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9684 KB Output is correct
2 Correct 10 ms 9836 KB Output is correct
3 Correct 12 ms 9836 KB Output is correct
4 Correct 12 ms 9844 KB Output is correct
5 Correct 12 ms 9976 KB Output is correct
6 Correct 12 ms 9976 KB Output is correct
7 Correct 12 ms 9976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9976 KB Output is correct
2 Correct 10 ms 10068 KB Output is correct
3 Correct 10 ms 10068 KB Output is correct
4 Correct 11 ms 10068 KB Output is correct
5 Correct 11 ms 10068 KB Output is correct
6 Correct 11 ms 10068 KB Output is correct
7 Correct 11 ms 10068 KB Output is correct
8 Correct 11 ms 10068 KB Output is correct
9 Correct 13 ms 10068 KB Output is correct
10 Correct 13 ms 10068 KB Output is correct
11 Correct 12 ms 10140 KB Output is correct
12 Correct 11 ms 10272 KB Output is correct
13 Correct 13 ms 10316 KB Output is correct
14 Correct 13 ms 10328 KB Output is correct
15 Correct 12 ms 10328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 10328 KB Output is correct
2 Correct 11 ms 10328 KB Output is correct
3 Correct 11 ms 10328 KB Output is correct
4 Correct 13 ms 10328 KB Output is correct
5 Correct 12 ms 10328 KB Output is correct
6 Correct 12 ms 10328 KB Output is correct
7 Correct 11 ms 10328 KB Output is correct
8 Correct 13 ms 10328 KB Output is correct
9 Correct 12 ms 10328 KB Output is correct
10 Correct 12 ms 10328 KB Output is correct
11 Correct 12 ms 10328 KB Output is correct
12 Correct 12 ms 10328 KB Output is correct
13 Correct 14 ms 10328 KB Output is correct
14 Correct 12 ms 10328 KB Output is correct
15 Correct 12 ms 10328 KB Output is correct
16 Correct 14 ms 10328 KB Output is correct
17 Correct 12 ms 10328 KB Output is correct
18 Correct 14 ms 10328 KB Output is correct
19 Correct 11 ms 10328 KB Output is correct
20 Correct 16 ms 10328 KB Output is correct
21 Correct 12 ms 10328 KB Output is correct
22 Correct 12 ms 10328 KB Output is correct
23 Correct 12 ms 10352 KB Output is correct
24 Correct 13 ms 10352 KB Output is correct
25 Correct 16 ms 10372 KB Output is correct
26 Correct 12 ms 10392 KB Output is correct
27 Correct 15 ms 10488 KB Output is correct
28 Correct 14 ms 10488 KB Output is correct
29 Correct 16 ms 10700 KB Output is correct
30 Correct 15 ms 10700 KB Output is correct
31 Correct 14 ms 10700 KB Output is correct
32 Correct 12 ms 10700 KB Output is correct
33 Correct 14 ms 10796 KB Output is correct
34 Correct 14 ms 10860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 10860 KB Output is correct
2 Correct 12 ms 10860 KB Output is correct
3 Correct 13 ms 10860 KB Output is correct
4 Correct 13 ms 10860 KB Output is correct
5 Correct 13 ms 10860 KB Output is correct
6 Correct 13 ms 10860 KB Output is correct
7 Correct 13 ms 10860 KB Output is correct
8 Correct 12 ms 10860 KB Output is correct
9 Correct 13 ms 10860 KB Output is correct
10 Correct 12 ms 10860 KB Output is correct
11 Correct 14 ms 10860 KB Output is correct
12 Correct 14 ms 10860 KB Output is correct
13 Correct 12 ms 10860 KB Output is correct
14 Correct 15 ms 10860 KB Output is correct
15 Correct 11 ms 10860 KB Output is correct
16 Correct 10 ms 10860 KB Output is correct
17 Correct 13 ms 10860 KB Output is correct
18 Correct 13 ms 10860 KB Output is correct
19 Correct 13 ms 10860 KB Output is correct
20 Correct 17 ms 10860 KB Output is correct
21 Correct 13 ms 10860 KB Output is correct
22 Correct 14 ms 10860 KB Output is correct
23 Correct 15 ms 10860 KB Output is correct
24 Correct 16 ms 10860 KB Output is correct
25 Correct 16 ms 10860 KB Output is correct
26 Correct 16 ms 10860 KB Output is correct
27 Correct 15 ms 10860 KB Output is correct
28 Correct 12 ms 10860 KB Output is correct
29 Correct 13 ms 10904 KB Output is correct
30 Correct 14 ms 10904 KB Output is correct
31 Correct 15 ms 10904 KB Output is correct
32 Correct 14 ms 10904 KB Output is correct
33 Correct 15 ms 11052 KB Output is correct
34 Correct 16 ms 11056 KB Output is correct
35 Correct 46 ms 11440 KB Output is correct
36 Correct 19 ms 11440 KB Output is correct
37 Correct 38 ms 11440 KB Output is correct
38 Correct 34 ms 11684 KB Output is correct
39 Correct 32 ms 11684 KB Output is correct
40 Correct 30 ms 11696 KB Output is correct
41 Correct 49 ms 11696 KB Output is correct
42 Correct 26 ms 11696 KB Output is correct
43 Correct 28 ms 11696 KB Output is correct
44 Correct 41 ms 11696 KB Output is correct
45 Correct 38 ms 11720 KB Output is correct
46 Correct 39 ms 11720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 11720 KB Output is correct
2 Correct 10 ms 11720 KB Output is correct
3 Correct 11 ms 11720 KB Output is correct
4 Correct 11 ms 11720 KB Output is correct
5 Correct 11 ms 11720 KB Output is correct
6 Correct 12 ms 11720 KB Output is correct
7 Correct 11 ms 11720 KB Output is correct
8 Correct 13 ms 11720 KB Output is correct
9 Correct 10 ms 11720 KB Output is correct
10 Correct 10 ms 11720 KB Output is correct
11 Correct 11 ms 11720 KB Output is correct
12 Correct 13 ms 11720 KB Output is correct
13 Correct 12 ms 11720 KB Output is correct
14 Correct 11 ms 11720 KB Output is correct
15 Correct 13 ms 11720 KB Output is correct
16 Correct 14 ms 11720 KB Output is correct
17 Correct 12 ms 11720 KB Output is correct
18 Correct 14 ms 11720 KB Output is correct
19 Correct 11 ms 11720 KB Output is correct
20 Correct 17 ms 11720 KB Output is correct
21 Correct 12 ms 11720 KB Output is correct
22 Correct 11 ms 11720 KB Output is correct
23 Correct 12 ms 11720 KB Output is correct
24 Correct 12 ms 11720 KB Output is correct
25 Correct 13 ms 11720 KB Output is correct
26 Correct 15 ms 11720 KB Output is correct
27 Correct 13 ms 11720 KB Output is correct
28 Correct 12 ms 11720 KB Output is correct
29 Correct 13 ms 11720 KB Output is correct
30 Correct 12 ms 11720 KB Output is correct
31 Correct 14 ms 11720 KB Output is correct
32 Correct 14 ms 11720 KB Output is correct
33 Correct 14 ms 11720 KB Output is correct
34 Correct 12 ms 11720 KB Output is correct
35 Correct 37 ms 11720 KB Output is correct
36 Correct 17 ms 11720 KB Output is correct
37 Correct 23 ms 11720 KB Output is correct
38 Correct 49 ms 11844 KB Output is correct
39 Correct 43 ms 11844 KB Output is correct
40 Correct 30 ms 11844 KB Output is correct
41 Correct 34 ms 11844 KB Output is correct
42 Correct 27 ms 11844 KB Output is correct
43 Correct 27 ms 11844 KB Output is correct
44 Correct 42 ms 11844 KB Output is correct
45 Correct 36 ms 11972 KB Output is correct
46 Correct 30 ms 11972 KB Output is correct
47 Correct 34 ms 12728 KB Output is correct
48 Correct 42 ms 12728 KB Output is correct
49 Correct 33 ms 12728 KB Output is correct
50 Correct 23 ms 12728 KB Output is correct
51 Correct 56 ms 14900 KB Output is correct
52 Correct 61 ms 14900 KB Output is correct
53 Correct 39 ms 14900 KB Output is correct
54 Correct 13 ms 14900 KB Output is correct
55 Correct 17 ms 14900 KB Output is correct
56 Execution timed out 1047 ms 14900 KB Time limit exceeded
57 Halted 0 ms 0 KB -