답안 #45916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45916 2018-04-16T13:21:54 Z Talant Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
900 ms 17596 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 () {
      scanf ("%lld%lld", &n,&m);

      for (int i = 1; i <= m; i ++) {
            scanf ("%lld%lld", &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) {
                  printf("%lld\n", d[v]);
                  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
             printf("%lld\n", d[b[2]]);
}

Compilation message

skyscraper.cpp:33:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:34:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf ("%lld%lld", &n,&m);
       ~~~~~~^~~~~~~~~~~~~~~~~~~
skyscraper.cpp:37:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf ("%lld%lld", &b[i],&p[i]);
             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9720 KB Output is correct
2 Correct 10 ms 9720 KB Output is correct
3 Correct 10 ms 9752 KB Output is correct
4 Correct 10 ms 9800 KB Output is correct
5 Correct 10 ms 9800 KB Output is correct
6 Correct 11 ms 9980 KB Output is correct
7 Correct 9 ms 9988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9988 KB Output is correct
2 Correct 9 ms 9988 KB Output is correct
3 Correct 11 ms 9988 KB Output is correct
4 Correct 9 ms 9988 KB Output is correct
5 Correct 9 ms 9988 KB Output is correct
6 Correct 9 ms 9988 KB Output is correct
7 Correct 9 ms 9988 KB Output is correct
8 Correct 9 ms 9988 KB Output is correct
9 Correct 9 ms 9988 KB Output is correct
10 Correct 9 ms 9988 KB Output is correct
11 Correct 10 ms 9988 KB Output is correct
12 Correct 10 ms 9988 KB Output is correct
13 Correct 10 ms 9988 KB Output is correct
14 Correct 10 ms 9988 KB Output is correct
15 Correct 10 ms 10084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10084 KB Output is correct
2 Correct 9 ms 10084 KB Output is correct
3 Correct 11 ms 10092 KB Output is correct
4 Correct 9 ms 10092 KB Output is correct
5 Correct 9 ms 10092 KB Output is correct
6 Correct 9 ms 10092 KB Output is correct
7 Correct 10 ms 10092 KB Output is correct
8 Correct 10 ms 10092 KB Output is correct
9 Correct 9 ms 10092 KB Output is correct
10 Correct 12 ms 10092 KB Output is correct
11 Correct 10 ms 10092 KB Output is correct
12 Correct 10 ms 10092 KB Output is correct
13 Correct 10 ms 10092 KB Output is correct
14 Correct 10 ms 10092 KB Output is correct
15 Correct 10 ms 10108 KB Output is correct
16 Correct 10 ms 10108 KB Output is correct
17 Correct 11 ms 10108 KB Output is correct
18 Correct 10 ms 10108 KB Output is correct
19 Correct 12 ms 10108 KB Output is correct
20 Correct 15 ms 10108 KB Output is correct
21 Correct 10 ms 10108 KB Output is correct
22 Correct 10 ms 10108 KB Output is correct
23 Correct 11 ms 10108 KB Output is correct
24 Correct 10 ms 10108 KB Output is correct
25 Correct 10 ms 10108 KB Output is correct
26 Correct 14 ms 10108 KB Output is correct
27 Correct 12 ms 10108 KB Output is correct
28 Correct 10 ms 10108 KB Output is correct
29 Correct 11 ms 10364 KB Output is correct
30 Correct 10 ms 10364 KB Output is correct
31 Correct 10 ms 10364 KB Output is correct
32 Correct 10 ms 10364 KB Output is correct
33 Correct 12 ms 10492 KB Output is correct
34 Correct 11 ms 10492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10492 KB Output is correct
2 Correct 9 ms 10492 KB Output is correct
3 Correct 9 ms 10492 KB Output is correct
4 Correct 10 ms 10492 KB Output is correct
5 Correct 11 ms 10492 KB Output is correct
6 Correct 12 ms 10492 KB Output is correct
7 Correct 12 ms 10492 KB Output is correct
8 Correct 10 ms 10492 KB Output is correct
9 Correct 9 ms 10492 KB Output is correct
10 Correct 12 ms 10492 KB Output is correct
11 Correct 11 ms 10492 KB Output is correct
12 Correct 10 ms 10492 KB Output is correct
13 Correct 12 ms 10492 KB Output is correct
14 Correct 12 ms 10492 KB Output is correct
15 Correct 12 ms 10492 KB Output is correct
16 Correct 10 ms 10492 KB Output is correct
17 Correct 11 ms 10492 KB Output is correct
18 Correct 12 ms 10492 KB Output is correct
19 Correct 10 ms 10492 KB Output is correct
20 Correct 22 ms 10492 KB Output is correct
21 Correct 10 ms 10492 KB Output is correct
22 Correct 10 ms 10492 KB Output is correct
23 Correct 11 ms 10492 KB Output is correct
24 Correct 14 ms 10492 KB Output is correct
25 Correct 12 ms 10492 KB Output is correct
26 Correct 14 ms 10492 KB Output is correct
27 Correct 10 ms 10492 KB Output is correct
28 Correct 12 ms 10492 KB Output is correct
29 Correct 12 ms 10492 KB Output is correct
30 Correct 13 ms 10492 KB Output is correct
31 Correct 11 ms 10492 KB Output is correct
32 Correct 14 ms 10492 KB Output is correct
33 Correct 12 ms 10492 KB Output is correct
34 Correct 14 ms 10492 KB Output is correct
35 Correct 27 ms 10876 KB Output is correct
36 Correct 12 ms 10876 KB Output is correct
37 Correct 20 ms 10876 KB Output is correct
38 Correct 22 ms 11132 KB Output is correct
39 Correct 22 ms 11132 KB Output is correct
40 Correct 28 ms 11132 KB Output is correct
41 Correct 29 ms 11132 KB Output is correct
42 Correct 23 ms 11132 KB Output is correct
43 Correct 19 ms 11132 KB Output is correct
44 Correct 26 ms 11132 KB Output is correct
45 Correct 21 ms 11260 KB Output is correct
46 Correct 20 ms 11260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 11260 KB Output is correct
2 Correct 11 ms 11260 KB Output is correct
3 Correct 11 ms 11260 KB Output is correct
4 Correct 12 ms 11260 KB Output is correct
5 Correct 12 ms 11260 KB Output is correct
6 Correct 10 ms 11260 KB Output is correct
7 Correct 9 ms 11260 KB Output is correct
8 Correct 12 ms 11260 KB Output is correct
9 Correct 12 ms 11260 KB Output is correct
10 Correct 10 ms 11260 KB Output is correct
11 Correct 10 ms 11260 KB Output is correct
12 Correct 9 ms 11260 KB Output is correct
13 Correct 10 ms 11260 KB Output is correct
14 Correct 10 ms 11260 KB Output is correct
15 Correct 10 ms 11260 KB Output is correct
16 Correct 9 ms 11260 KB Output is correct
17 Correct 11 ms 11260 KB Output is correct
18 Correct 10 ms 11260 KB Output is correct
19 Correct 10 ms 11260 KB Output is correct
20 Correct 17 ms 11260 KB Output is correct
21 Correct 10 ms 11260 KB Output is correct
22 Correct 11 ms 11260 KB Output is correct
23 Correct 13 ms 11260 KB Output is correct
24 Correct 14 ms 11260 KB Output is correct
25 Correct 11 ms 11260 KB Output is correct
26 Correct 11 ms 11260 KB Output is correct
27 Correct 11 ms 11260 KB Output is correct
28 Correct 10 ms 11260 KB Output is correct
29 Correct 11 ms 11260 KB Output is correct
30 Correct 11 ms 11260 KB Output is correct
31 Correct 12 ms 11260 KB Output is correct
32 Correct 13 ms 11260 KB Output is correct
33 Correct 16 ms 11260 KB Output is correct
34 Correct 12 ms 11260 KB Output is correct
35 Correct 21 ms 11260 KB Output is correct
36 Correct 15 ms 11260 KB Output is correct
37 Correct 18 ms 11260 KB Output is correct
38 Correct 22 ms 11260 KB Output is correct
39 Correct 19 ms 11260 KB Output is correct
40 Correct 29 ms 11260 KB Output is correct
41 Correct 20 ms 11260 KB Output is correct
42 Correct 18 ms 11260 KB Output is correct
43 Correct 19 ms 11260 KB Output is correct
44 Correct 22 ms 11260 KB Output is correct
45 Correct 30 ms 11260 KB Output is correct
46 Correct 21 ms 11260 KB Output is correct
47 Correct 24 ms 12020 KB Output is correct
48 Correct 25 ms 12020 KB Output is correct
49 Correct 19 ms 12020 KB Output is correct
50 Correct 16 ms 12020 KB Output is correct
51 Correct 38 ms 13556 KB Output is correct
52 Correct 34 ms 13556 KB Output is correct
53 Correct 23 ms 13556 KB Output is correct
54 Correct 12 ms 13556 KB Output is correct
55 Correct 13 ms 13556 KB Output is correct
56 Correct 900 ms 13556 KB Output is correct
57 Correct 16 ms 13556 KB Output is correct
58 Correct 22 ms 13556 KB Output is correct
59 Correct 23 ms 13556 KB Output is correct
60 Correct 19 ms 13556 KB Output is correct
61 Correct 20 ms 13556 KB Output is correct
62 Correct 25 ms 13556 KB Output is correct
63 Correct 44 ms 14764 KB Output is correct
64 Correct 45 ms 14880 KB Output is correct
65 Correct 50 ms 15240 KB Output is correct
66 Correct 79 ms 17384 KB Output is correct
67 Correct 56 ms 17596 KB Output is correct