Submission #45802

# Submission time Handle Problem Language Result Execution time Memory
45802 2018-04-16T06:35:21 Z Talant Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 75132 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;

            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 9 ms 9828 KB Output is correct
3 Correct 9 ms 9828 KB Output is correct
4 Correct 10 ms 9920 KB Output is correct
5 Correct 9 ms 9920 KB Output is correct
6 Correct 10 ms 9920 KB Output is correct
7 Correct 10 ms 9972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9972 KB Output is correct
2 Correct 10 ms 9972 KB Output is correct
3 Correct 11 ms 9972 KB Output is correct
4 Correct 9 ms 9972 KB Output is correct
5 Correct 9 ms 9980 KB Output is correct
6 Correct 9 ms 9980 KB Output is correct
7 Correct 9 ms 9980 KB Output is correct
8 Correct 10 ms 9980 KB Output is correct
9 Correct 10 ms 9980 KB Output is correct
10 Correct 11 ms 9980 KB Output is correct
11 Correct 15 ms 10108 KB Output is correct
12 Correct 13 ms 10108 KB Output is correct
13 Correct 13 ms 10236 KB Output is correct
14 Correct 14 ms 10236 KB Output is correct
15 Correct 13 ms 10236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 10236 KB Output is correct
2 Correct 9 ms 10236 KB Output is correct
3 Correct 10 ms 10236 KB Output is correct
4 Correct 9 ms 10236 KB Output is correct
5 Correct 9 ms 10236 KB Output is correct
6 Correct 11 ms 10236 KB Output is correct
7 Correct 10 ms 10236 KB Output is correct
8 Correct 10 ms 10236 KB Output is correct
9 Correct 10 ms 10236 KB Output is correct
10 Correct 11 ms 10236 KB Output is correct
11 Correct 13 ms 10236 KB Output is correct
12 Correct 14 ms 10236 KB Output is correct
13 Correct 14 ms 10236 KB Output is correct
14 Correct 13 ms 10236 KB Output is correct
15 Correct 13 ms 10236 KB Output is correct
16 Correct 13 ms 10236 KB Output is correct
17 Correct 32 ms 10492 KB Output is correct
18 Correct 38 ms 10492 KB Output is correct
19 Correct 30 ms 10492 KB Output is correct
20 Correct 156 ms 74324 KB Output is correct
21 Correct 17 ms 74324 KB Output is correct
22 Correct 32 ms 74324 KB Output is correct
23 Correct 36 ms 74324 KB Output is correct
24 Correct 65 ms 74324 KB Output is correct
25 Correct 70 ms 74324 KB Output is correct
26 Correct 62 ms 74324 KB Output is correct
27 Correct 63 ms 74324 KB Output is correct
28 Correct 72 ms 74324 KB Output is correct
29 Correct 35 ms 74324 KB Output is correct
30 Correct 20 ms 74324 KB Output is correct
31 Correct 29 ms 74324 KB Output is correct
32 Correct 27 ms 74324 KB Output is correct
33 Correct 82 ms 74324 KB Output is correct
34 Correct 67 ms 74324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 74324 KB Output is correct
2 Correct 10 ms 74324 KB Output is correct
3 Correct 9 ms 74324 KB Output is correct
4 Correct 11 ms 74324 KB Output is correct
5 Correct 9 ms 74324 KB Output is correct
6 Correct 12 ms 74324 KB Output is correct
7 Correct 10 ms 74324 KB Output is correct
8 Correct 9 ms 74324 KB Output is correct
9 Correct 9 ms 74324 KB Output is correct
10 Correct 11 ms 74324 KB Output is correct
11 Correct 18 ms 74324 KB Output is correct
12 Correct 15 ms 74324 KB Output is correct
13 Correct 14 ms 74324 KB Output is correct
14 Correct 14 ms 74324 KB Output is correct
15 Correct 14 ms 74324 KB Output is correct
16 Correct 13 ms 74324 KB Output is correct
17 Correct 31 ms 74324 KB Output is correct
18 Correct 39 ms 74324 KB Output is correct
19 Correct 29 ms 74324 KB Output is correct
20 Correct 168 ms 74324 KB Output is correct
21 Correct 16 ms 74324 KB Output is correct
22 Correct 37 ms 74324 KB Output is correct
23 Correct 34 ms 74324 KB Output is correct
24 Correct 70 ms 74324 KB Output is correct
25 Correct 73 ms 74324 KB Output is correct
26 Correct 69 ms 74324 KB Output is correct
27 Correct 62 ms 74324 KB Output is correct
28 Correct 75 ms 74324 KB Output is correct
29 Correct 40 ms 74324 KB Output is correct
30 Correct 19 ms 74324 KB Output is correct
31 Correct 30 ms 74324 KB Output is correct
32 Correct 27 ms 74324 KB Output is correct
33 Correct 67 ms 74324 KB Output is correct
34 Correct 67 ms 74324 KB Output is correct
35 Correct 475 ms 74324 KB Output is correct
36 Correct 84 ms 74324 KB Output is correct
37 Correct 499 ms 74324 KB Output is correct
38 Correct 795 ms 74324 KB Output is correct
39 Correct 784 ms 74324 KB Output is correct
40 Correct 790 ms 74324 KB Output is correct
41 Correct 899 ms 74324 KB Output is correct
42 Correct 783 ms 74324 KB Output is correct
43 Correct 777 ms 74324 KB Output is correct
44 Correct 831 ms 75000 KB Output is correct
45 Correct 783 ms 75000 KB Output is correct
46 Correct 858 ms 75000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 75000 KB Output is correct
2 Correct 9 ms 75000 KB Output is correct
3 Correct 9 ms 75000 KB Output is correct
4 Correct 12 ms 75000 KB Output is correct
5 Correct 9 ms 75000 KB Output is correct
6 Correct 9 ms 75000 KB Output is correct
7 Correct 11 ms 75000 KB Output is correct
8 Correct 9 ms 75000 KB Output is correct
9 Correct 12 ms 75000 KB Output is correct
10 Correct 11 ms 75000 KB Output is correct
11 Correct 14 ms 75000 KB Output is correct
12 Correct 14 ms 75000 KB Output is correct
13 Correct 15 ms 75000 KB Output is correct
14 Correct 13 ms 75000 KB Output is correct
15 Correct 14 ms 75000 KB Output is correct
16 Correct 16 ms 75000 KB Output is correct
17 Correct 40 ms 75000 KB Output is correct
18 Correct 37 ms 75000 KB Output is correct
19 Correct 41 ms 75000 KB Output is correct
20 Correct 157 ms 75000 KB Output is correct
21 Correct 16 ms 75000 KB Output is correct
22 Correct 31 ms 75000 KB Output is correct
23 Correct 34 ms 75000 KB Output is correct
24 Correct 69 ms 75000 KB Output is correct
25 Correct 103 ms 75000 KB Output is correct
26 Correct 65 ms 75000 KB Output is correct
27 Correct 62 ms 75000 KB Output is correct
28 Correct 73 ms 75000 KB Output is correct
29 Correct 36 ms 75000 KB Output is correct
30 Correct 22 ms 75000 KB Output is correct
31 Correct 30 ms 75000 KB Output is correct
32 Correct 27 ms 75000 KB Output is correct
33 Correct 71 ms 75000 KB Output is correct
34 Correct 67 ms 75000 KB Output is correct
35 Correct 507 ms 75000 KB Output is correct
36 Correct 83 ms 75000 KB Output is correct
37 Correct 518 ms 75000 KB Output is correct
38 Correct 770 ms 75000 KB Output is correct
39 Correct 796 ms 75000 KB Output is correct
40 Correct 781 ms 75000 KB Output is correct
41 Correct 775 ms 75000 KB Output is correct
42 Correct 747 ms 75000 KB Output is correct
43 Correct 834 ms 75000 KB Output is correct
44 Correct 837 ms 75132 KB Output is correct
45 Correct 858 ms 75132 KB Output is correct
46 Correct 812 ms 75132 KB Output is correct
47 Execution timed out 1084 ms 75132 KB Time limit exceeded
48 Halted 0 ms 0 KB -