Submission #45907

# Submission time Handle Problem Language Result Execution time Memory
45907 2018-04-16T13:07:30 Z Talant Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 75080 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 ++) {
            for (int j = 1; j <= n; j ++) {
                  int mnn = inf;
                  if (i == j)
                        continue;
                  for (auto to : vec[i]) {
                        if (check(i,j,to))
                              mnn = min(mnn,f(i,j,to));
                  }
                  if (mnn != inf)
                        g[i].pb(mk(j,mnn));
            }
      }
      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 : g[v]) {
                  if (d[v] + to.sc < d[to.fr]) {
                        d[to.fr] = d[v] + to.sc;
                        q.push({-d[to.fr],to.fr});
                  }
            }
      }
      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 () {
       ^
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9720 KB Output is correct
2 Correct 11 ms 9720 KB Output is correct
3 Correct 11 ms 9736 KB Output is correct
4 Correct 9 ms 9780 KB Output is correct
5 Correct 10 ms 9844 KB Output is correct
6 Correct 10 ms 9844 KB Output is correct
7 Correct 11 ms 9912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9912 KB Output is correct
2 Correct 12 ms 9936 KB Output is correct
3 Correct 12 ms 9960 KB Output is correct
4 Correct 11 ms 9960 KB Output is correct
5 Correct 12 ms 10016 KB Output is correct
6 Correct 11 ms 10016 KB Output is correct
7 Correct 9 ms 10016 KB Output is correct
8 Correct 9 ms 10016 KB Output is correct
9 Correct 13 ms 10016 KB Output is correct
10 Correct 11 ms 10016 KB Output is correct
11 Correct 14 ms 10084 KB Output is correct
12 Correct 18 ms 10084 KB Output is correct
13 Correct 15 ms 10212 KB Output is correct
14 Correct 14 ms 10212 KB Output is correct
15 Correct 14 ms 10212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10212 KB Output is correct
2 Correct 10 ms 10212 KB Output is correct
3 Correct 9 ms 10212 KB Output is correct
4 Correct 9 ms 10212 KB Output is correct
5 Correct 10 ms 10212 KB Output is correct
6 Correct 9 ms 10212 KB Output is correct
7 Correct 9 ms 10212 KB Output is correct
8 Correct 9 ms 10212 KB Output is correct
9 Correct 10 ms 10212 KB Output is correct
10 Correct 10 ms 10212 KB Output is correct
11 Correct 18 ms 10212 KB Output is correct
12 Correct 17 ms 10212 KB Output is correct
13 Correct 17 ms 10236 KB Output is correct
14 Correct 13 ms 10236 KB Output is correct
15 Correct 16 ms 10236 KB Output is correct
16 Correct 16 ms 10236 KB Output is correct
17 Correct 35 ms 10492 KB Output is correct
18 Correct 48 ms 10492 KB Output is correct
19 Correct 30 ms 10492 KB Output is correct
20 Correct 160 ms 74276 KB Output is correct
21 Correct 17 ms 74276 KB Output is correct
22 Correct 31 ms 74276 KB Output is correct
23 Correct 47 ms 74276 KB Output is correct
24 Correct 75 ms 74276 KB Output is correct
25 Correct 91 ms 74276 KB Output is correct
26 Correct 63 ms 74276 KB Output is correct
27 Correct 62 ms 74276 KB Output is correct
28 Correct 102 ms 74276 KB Output is correct
29 Correct 48 ms 74276 KB Output is correct
30 Correct 26 ms 74276 KB Output is correct
31 Correct 40 ms 74276 KB Output is correct
32 Correct 27 ms 74276 KB Output is correct
33 Correct 82 ms 74276 KB Output is correct
34 Correct 67 ms 74276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 74276 KB Output is correct
2 Correct 9 ms 74276 KB Output is correct
3 Correct 9 ms 74276 KB Output is correct
4 Correct 11 ms 74276 KB Output is correct
5 Correct 10 ms 74276 KB Output is correct
6 Correct 9 ms 74276 KB Output is correct
7 Correct 9 ms 74276 KB Output is correct
8 Correct 9 ms 74276 KB Output is correct
9 Correct 10 ms 74276 KB Output is correct
10 Correct 14 ms 74276 KB Output is correct
11 Correct 18 ms 74276 KB Output is correct
12 Correct 17 ms 74276 KB Output is correct
13 Correct 18 ms 74276 KB Output is correct
14 Correct 17 ms 74276 KB Output is correct
15 Correct 14 ms 74276 KB Output is correct
16 Correct 15 ms 74276 KB Output is correct
17 Correct 30 ms 74276 KB Output is correct
18 Correct 58 ms 74276 KB Output is correct
19 Correct 35 ms 74276 KB Output is correct
20 Correct 170 ms 74276 KB Output is correct
21 Correct 19 ms 74276 KB Output is correct
22 Correct 33 ms 74276 KB Output is correct
23 Correct 35 ms 74276 KB Output is correct
24 Correct 81 ms 74276 KB Output is correct
25 Correct 75 ms 74276 KB Output is correct
26 Correct 62 ms 74276 KB Output is correct
27 Correct 63 ms 74276 KB Output is correct
28 Correct 75 ms 74276 KB Output is correct
29 Correct 36 ms 74276 KB Output is correct
30 Correct 19 ms 74276 KB Output is correct
31 Correct 30 ms 74276 KB Output is correct
32 Correct 30 ms 74276 KB Output is correct
33 Correct 72 ms 74276 KB Output is correct
34 Correct 76 ms 74276 KB Output is correct
35 Correct 508 ms 74276 KB Output is correct
36 Correct 86 ms 74276 KB Output is correct
37 Correct 499 ms 74276 KB Output is correct
38 Correct 783 ms 74276 KB Output is correct
39 Correct 770 ms 74276 KB Output is correct
40 Correct 809 ms 74276 KB Output is correct
41 Correct 838 ms 74276 KB Output is correct
42 Correct 785 ms 74276 KB Output is correct
43 Correct 826 ms 74276 KB Output is correct
44 Correct 854 ms 75080 KB Output is correct
45 Correct 858 ms 75080 KB Output is correct
46 Correct 770 ms 75080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 75080 KB Output is correct
2 Correct 9 ms 75080 KB Output is correct
3 Correct 9 ms 75080 KB Output is correct
4 Correct 11 ms 75080 KB Output is correct
5 Correct 10 ms 75080 KB Output is correct
6 Correct 10 ms 75080 KB Output is correct
7 Correct 10 ms 75080 KB Output is correct
8 Correct 11 ms 75080 KB Output is correct
9 Correct 9 ms 75080 KB Output is correct
10 Correct 10 ms 75080 KB Output is correct
11 Correct 17 ms 75080 KB Output is correct
12 Correct 16 ms 75080 KB Output is correct
13 Correct 13 ms 75080 KB Output is correct
14 Correct 18 ms 75080 KB Output is correct
15 Correct 14 ms 75080 KB Output is correct
16 Correct 16 ms 75080 KB Output is correct
17 Correct 29 ms 75080 KB Output is correct
18 Correct 37 ms 75080 KB Output is correct
19 Correct 33 ms 75080 KB Output is correct
20 Correct 155 ms 75080 KB Output is correct
21 Correct 16 ms 75080 KB Output is correct
22 Correct 33 ms 75080 KB Output is correct
23 Correct 46 ms 75080 KB Output is correct
24 Correct 69 ms 75080 KB Output is correct
25 Correct 70 ms 75080 KB Output is correct
26 Correct 66 ms 75080 KB Output is correct
27 Correct 68 ms 75080 KB Output is correct
28 Correct 84 ms 75080 KB Output is correct
29 Correct 51 ms 75080 KB Output is correct
30 Correct 20 ms 75080 KB Output is correct
31 Correct 32 ms 75080 KB Output is correct
32 Correct 35 ms 75080 KB Output is correct
33 Correct 90 ms 75080 KB Output is correct
34 Correct 69 ms 75080 KB Output is correct
35 Correct 528 ms 75080 KB Output is correct
36 Correct 104 ms 75080 KB Output is correct
37 Correct 605 ms 75080 KB Output is correct
38 Correct 787 ms 75080 KB Output is correct
39 Correct 817 ms 75080 KB Output is correct
40 Correct 809 ms 75080 KB Output is correct
41 Correct 791 ms 75080 KB Output is correct
42 Correct 754 ms 75080 KB Output is correct
43 Correct 778 ms 75080 KB Output is correct
44 Correct 885 ms 75080 KB Output is correct
45 Correct 859 ms 75080 KB Output is correct
46 Correct 824 ms 75080 KB Output is correct
47 Execution timed out 1079 ms 75080 KB Time limit exceeded
48 Halted 0 ms 0 KB -