답안 #45931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45931 2018-04-16T13:51:04 Z TheDarkning Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
882 ms 15220 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 9 ms 9836 KB Output is correct
3 Correct 9 ms 9836 KB Output is correct
4 Correct 9 ms 9836 KB Output is correct
5 Correct 9 ms 9884 KB Output is correct
6 Correct 9 ms 9940 KB Output is correct
7 Correct 9 ms 10068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10068 KB Output is correct
2 Correct 9 ms 10068 KB Output is correct
3 Correct 9 ms 10068 KB Output is correct
4 Correct 11 ms 10068 KB Output is correct
5 Correct 10 ms 10068 KB Output is correct
6 Correct 10 ms 10068 KB Output is correct
7 Correct 10 ms 10092 KB Output is correct
8 Correct 12 ms 10092 KB Output is correct
9 Correct 10 ms 10092 KB Output is correct
10 Correct 11 ms 10092 KB Output is correct
11 Correct 11 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 10092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10092 KB Output is correct
2 Correct 10 ms 10092 KB Output is correct
3 Correct 12 ms 10092 KB Output is correct
4 Correct 9 ms 10092 KB Output is correct
5 Correct 11 ms 10092 KB Output is correct
6 Correct 10 ms 10092 KB Output is correct
7 Correct 9 ms 10092 KB Output is correct
8 Correct 9 ms 10092 KB Output is correct
9 Correct 9 ms 10092 KB Output is correct
10 Correct 10 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 11 ms 10092 KB Output is correct
15 Correct 10 ms 10092 KB Output is correct
16 Correct 12 ms 10092 KB Output is correct
17 Correct 10 ms 10108 KB Output is correct
18 Correct 10 ms 10108 KB Output is correct
19 Correct 11 ms 10108 KB Output is correct
20 Correct 14 ms 10108 KB Output is correct
21 Correct 11 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 11 ms 10108 KB Output is correct
25 Correct 14 ms 10108 KB Output is correct
26 Correct 11 ms 10108 KB Output is correct
27 Correct 10 ms 10108 KB Output is correct
28 Correct 13 ms 10236 KB Output is correct
29 Correct 12 ms 10364 KB Output is correct
30 Correct 11 ms 10364 KB Output is correct
31 Correct 11 ms 10364 KB Output is correct
32 Correct 10 ms 10364 KB Output is correct
33 Correct 13 ms 10492 KB Output is correct
34 Correct 12 ms 10492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10492 KB Output is correct
2 Correct 11 ms 10492 KB Output is correct
3 Correct 10 ms 10492 KB Output is correct
4 Correct 12 ms 10492 KB Output is correct
5 Correct 11 ms 10492 KB Output is correct
6 Correct 9 ms 10492 KB Output is correct
7 Correct 10 ms 10492 KB Output is correct
8 Correct 10 ms 10492 KB Output is correct
9 Correct 12 ms 10492 KB Output is correct
10 Correct 10 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 10 ms 10492 KB Output is correct
14 Correct 10 ms 10492 KB Output is correct
15 Correct 11 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 10 ms 10492 KB Output is correct
19 Correct 12 ms 10492 KB Output is correct
20 Correct 15 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 11 ms 10492 KB Output is correct
25 Correct 11 ms 10492 KB Output is correct
26 Correct 13 ms 10492 KB Output is correct
27 Correct 10 ms 10492 KB Output is correct
28 Correct 10 ms 10492 KB Output is correct
29 Correct 15 ms 10492 KB Output is correct
30 Correct 10 ms 10492 KB Output is correct
31 Correct 11 ms 10492 KB Output is correct
32 Correct 11 ms 10492 KB Output is correct
33 Correct 15 ms 10492 KB Output is correct
34 Correct 14 ms 10496 KB Output is correct
35 Correct 21 ms 10876 KB Output is correct
36 Correct 11 ms 10876 KB Output is correct
37 Correct 17 ms 10876 KB Output is correct
38 Correct 22 ms 11132 KB Output is correct
39 Correct 19 ms 11132 KB Output is correct
40 Correct 20 ms 11256 KB Output is correct
41 Correct 33 ms 11256 KB Output is correct
42 Correct 24 ms 11256 KB Output is correct
43 Correct 26 ms 11256 KB Output is correct
44 Correct 22 ms 11256 KB Output is correct
45 Correct 25 ms 11320 KB Output is correct
46 Correct 29 ms 11320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 11320 KB Output is correct
2 Correct 10 ms 11320 KB Output is correct
3 Correct 11 ms 11320 KB Output is correct
4 Correct 12 ms 11320 KB Output is correct
5 Correct 12 ms 11320 KB Output is correct
6 Correct 10 ms 11320 KB Output is correct
7 Correct 10 ms 11320 KB Output is correct
8 Correct 10 ms 11320 KB Output is correct
9 Correct 10 ms 11320 KB Output is correct
10 Correct 10 ms 11320 KB Output is correct
11 Correct 10 ms 11320 KB Output is correct
12 Correct 10 ms 11320 KB Output is correct
13 Correct 10 ms 11320 KB Output is correct
14 Correct 13 ms 11320 KB Output is correct
15 Correct 10 ms 11320 KB Output is correct
16 Correct 10 ms 11320 KB Output is correct
17 Correct 11 ms 11320 KB Output is correct
18 Correct 12 ms 11320 KB Output is correct
19 Correct 9 ms 11320 KB Output is correct
20 Correct 16 ms 11320 KB Output is correct
21 Correct 10 ms 11320 KB Output is correct
22 Correct 9 ms 11320 KB Output is correct
23 Correct 10 ms 11320 KB Output is correct
24 Correct 11 ms 11320 KB Output is correct
25 Correct 11 ms 11320 KB Output is correct
26 Correct 10 ms 11320 KB Output is correct
27 Correct 12 ms 11320 KB Output is correct
28 Correct 10 ms 11320 KB Output is correct
29 Correct 13 ms 11320 KB Output is correct
30 Correct 10 ms 11320 KB Output is correct
31 Correct 10 ms 11320 KB Output is correct
32 Correct 11 ms 11320 KB Output is correct
33 Correct 12 ms 11320 KB Output is correct
34 Correct 11 ms 11320 KB Output is correct
35 Correct 19 ms 11320 KB Output is correct
36 Correct 11 ms 11320 KB Output is correct
37 Correct 24 ms 11320 KB Output is correct
38 Correct 20 ms 11320 KB Output is correct
39 Correct 22 ms 11320 KB Output is correct
40 Correct 20 ms 11320 KB Output is correct
41 Correct 21 ms 11320 KB Output is correct
42 Correct 17 ms 11320 KB Output is correct
43 Correct 16 ms 11320 KB Output is correct
44 Correct 20 ms 11320 KB Output is correct
45 Correct 21 ms 11320 KB Output is correct
46 Correct 19 ms 11320 KB Output is correct
47 Correct 22 ms 12200 KB Output is correct
48 Correct 19 ms 12200 KB Output is correct
49 Correct 18 ms 12200 KB Output is correct
50 Correct 16 ms 12200 KB Output is correct
51 Correct 36 ms 13556 KB Output is correct
52 Correct 34 ms 13556 KB Output is correct
53 Correct 24 ms 13556 KB Output is correct
54 Correct 12 ms 13556 KB Output is correct
55 Correct 12 ms 13556 KB Output is correct
56 Correct 882 ms 13556 KB Output is correct
57 Correct 15 ms 13556 KB Output is correct
58 Correct 20 ms 13556 KB Output is correct
59 Correct 26 ms 13556 KB Output is correct
60 Correct 19 ms 13556 KB Output is correct
61 Correct 31 ms 13556 KB Output is correct
62 Correct 27 ms 13556 KB Output is correct
63 Correct 45 ms 13556 KB Output is correct
64 Correct 43 ms 13556 KB Output is correct
65 Correct 48 ms 13556 KB Output is correct
66 Correct 83 ms 15220 KB Output is correct
67 Correct 58 ms 15220 KB Output is correct