Submission #60482

# Submission time Handle Problem Language Result Execution time Memory
60482 2018-07-24T08:56:19 Z dukati8 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 6696 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a; i<int(b); i++)
#define all(x) x.begin(),x.end()

int main() {
  int n,m;
  cin >> n >> m;
  vector<pair<int,int> > doges(m);
  vector<unordered_set<int> > scrapers(n); //For each scraper a set of all dogs that reside there from beginning, or rather their jumps
  rep(i,0,m) {
    int b,p;
    cin >> b >> p;
    doges[i]=make_pair(b,abs(p));
    scrapers[b].insert(p);
  }
  priority_queue<vector<int> > order; //Each element is <numjumps,position, jumplen, 1 or 0 for left/right>
  int dp[n];
  rep (i,0,n) dp[i]=1000000000;
  int start,stop;
  start=doges[0].first;
  stop=doges[1].first;
  dp[start]=0;
  for (auto p:scrapers[start]) {
    order.push({0,start,p,1});
    order.push({0,start,p,0});
  }
  while (!order.empty()) {
    auto curr =order.top();
    order.pop();
    int num,pos,p;
    num=-curr[0];
    pos=curr[1];
    if (pos==stop) break;
    p=curr[2];
    bool left = curr[3]==1;
    int next;
    if (left) next=pos+p;
    else next=pos-p;
    if (next>=0 && next<n) {
      if (dp[next]>num+1) {
        dp[next]=num+1;
        for (auto pn:scrapers[next]){
          if (pn!=p) {
            order.push({-num-1,next,pn,1});
            order.push({-num-1,next,pn,0});
          }
        }
        order.push({-num-1,next,p,curr[3]});
      }
      else if (scrapers[next].find(p)==scrapers[next].end()) {
        order.push({-num-1,next,p,curr[3]});
      }
    }
  }
  if (dp[stop] == 1000000000) cout << -1 << endl;
  else cout << dp[stop]<< endl;

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 696 KB Output is correct
2 Correct 3 ms 696 KB Output is correct
3 Correct 4 ms 696 KB Output is correct
4 Correct 4 ms 696 KB Output is correct
5 Correct 2 ms 696 KB Output is correct
6 Correct 2 ms 696 KB Output is correct
7 Correct 3 ms 696 KB Output is correct
8 Correct 2 ms 696 KB Output is correct
9 Correct 3 ms 696 KB Output is correct
10 Correct 3 ms 696 KB Output is correct
11 Correct 6 ms 764 KB Output is correct
12 Correct 4 ms 764 KB Output is correct
13 Correct 3 ms 764 KB Output is correct
14 Correct 7 ms 892 KB Output is correct
15 Correct 10 ms 892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 892 KB Output is correct
2 Correct 3 ms 892 KB Output is correct
3 Correct 2 ms 892 KB Output is correct
4 Correct 3 ms 892 KB Output is correct
5 Correct 3 ms 892 KB Output is correct
6 Correct 0 ms 892 KB Output is correct
7 Correct 2 ms 892 KB Output is correct
8 Correct 3 ms 892 KB Output is correct
9 Correct 3 ms 892 KB Output is correct
10 Correct 3 ms 892 KB Output is correct
11 Correct 5 ms 892 KB Output is correct
12 Correct 5 ms 892 KB Output is correct
13 Correct 4 ms 892 KB Output is correct
14 Correct 8 ms 892 KB Output is correct
15 Correct 7 ms 892 KB Output is correct
16 Correct 4 ms 892 KB Output is correct
17 Correct 7 ms 892 KB Output is correct
18 Correct 3 ms 892 KB Output is correct
19 Correct 4 ms 892 KB Output is correct
20 Correct 5 ms 892 KB Output is correct
21 Correct 3 ms 892 KB Output is correct
22 Correct 4 ms 892 KB Output is correct
23 Correct 5 ms 892 KB Output is correct
24 Correct 7 ms 892 KB Output is correct
25 Correct 6 ms 892 KB Output is correct
26 Correct 5 ms 892 KB Output is correct
27 Correct 5 ms 892 KB Output is correct
28 Correct 8 ms 892 KB Output is correct
29 Correct 32 ms 892 KB Output is correct
30 Correct 9 ms 892 KB Output is correct
31 Correct 13 ms 892 KB Output is correct
32 Correct 9 ms 892 KB Output is correct
33 Correct 58 ms 1148 KB Output is correct
34 Correct 32 ms 1148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1148 KB Output is correct
2 Correct 2 ms 1148 KB Output is correct
3 Correct 2 ms 1148 KB Output is correct
4 Correct 3 ms 1148 KB Output is correct
5 Correct 3 ms 1148 KB Output is correct
6 Correct 2 ms 1148 KB Output is correct
7 Correct 2 ms 1148 KB Output is correct
8 Correct 3 ms 1148 KB Output is correct
9 Correct 3 ms 1148 KB Output is correct
10 Correct 3 ms 1148 KB Output is correct
11 Correct 2 ms 1148 KB Output is correct
12 Correct 4 ms 1148 KB Output is correct
13 Correct 4 ms 1148 KB Output is correct
14 Correct 8 ms 1148 KB Output is correct
15 Correct 5 ms 1148 KB Output is correct
16 Correct 3 ms 1148 KB Output is correct
17 Correct 6 ms 1148 KB Output is correct
18 Correct 4 ms 1148 KB Output is correct
19 Correct 4 ms 1148 KB Output is correct
20 Correct 7 ms 1148 KB Output is correct
21 Correct 6 ms 1148 KB Output is correct
22 Correct 4 ms 1148 KB Output is correct
23 Correct 5 ms 1148 KB Output is correct
24 Correct 7 ms 1148 KB Output is correct
25 Correct 8 ms 1148 KB Output is correct
26 Correct 4 ms 1148 KB Output is correct
27 Correct 5 ms 1148 KB Output is correct
28 Correct 11 ms 1148 KB Output is correct
29 Correct 31 ms 1148 KB Output is correct
30 Correct 11 ms 1148 KB Output is correct
31 Correct 12 ms 1148 KB Output is correct
32 Correct 9 ms 1148 KB Output is correct
33 Correct 52 ms 1148 KB Output is correct
34 Correct 29 ms 1148 KB Output is correct
35 Correct 81 ms 4620 KB Output is correct
36 Correct 10 ms 4620 KB Output is correct
37 Correct 58 ms 4620 KB Output is correct
38 Correct 148 ms 5168 KB Output is correct
39 Correct 54 ms 5168 KB Output is correct
40 Correct 81 ms 5168 KB Output is correct
41 Correct 134 ms 5168 KB Output is correct
42 Correct 22 ms 5168 KB Output is correct
43 Correct 20 ms 5168 KB Output is correct
44 Correct 25 ms 5168 KB Output is correct
45 Correct 462 ms 5552 KB Output is correct
46 Correct 286 ms 5616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5616 KB Output is correct
2 Correct 2 ms 5616 KB Output is correct
3 Correct 3 ms 5616 KB Output is correct
4 Correct 3 ms 5616 KB Output is correct
5 Correct 3 ms 5616 KB Output is correct
6 Correct 3 ms 5616 KB Output is correct
7 Correct 3 ms 5616 KB Output is correct
8 Correct 3 ms 5616 KB Output is correct
9 Correct 2 ms 5616 KB Output is correct
10 Correct 4 ms 5616 KB Output is correct
11 Correct 5 ms 5616 KB Output is correct
12 Correct 4 ms 5616 KB Output is correct
13 Correct 5 ms 5616 KB Output is correct
14 Correct 7 ms 5616 KB Output is correct
15 Correct 7 ms 5616 KB Output is correct
16 Correct 4 ms 5616 KB Output is correct
17 Correct 7 ms 5616 KB Output is correct
18 Correct 4 ms 5616 KB Output is correct
19 Correct 3 ms 5616 KB Output is correct
20 Correct 7 ms 5616 KB Output is correct
21 Correct 3 ms 5616 KB Output is correct
22 Correct 3 ms 5616 KB Output is correct
23 Correct 7 ms 5616 KB Output is correct
24 Correct 11 ms 5616 KB Output is correct
25 Correct 5 ms 5616 KB Output is correct
26 Correct 5 ms 5616 KB Output is correct
27 Correct 6 ms 5616 KB Output is correct
28 Correct 10 ms 5616 KB Output is correct
29 Correct 19 ms 5616 KB Output is correct
30 Correct 9 ms 5616 KB Output is correct
31 Correct 14 ms 5616 KB Output is correct
32 Correct 10 ms 5616 KB Output is correct
33 Correct 54 ms 5616 KB Output is correct
34 Correct 34 ms 5616 KB Output is correct
35 Correct 83 ms 5616 KB Output is correct
36 Correct 7 ms 5616 KB Output is correct
37 Correct 48 ms 5616 KB Output is correct
38 Correct 126 ms 5616 KB Output is correct
39 Correct 61 ms 5616 KB Output is correct
40 Correct 70 ms 5616 KB Output is correct
41 Correct 103 ms 5616 KB Output is correct
42 Correct 22 ms 5616 KB Output is correct
43 Correct 28 ms 5616 KB Output is correct
44 Correct 23 ms 5616 KB Output is correct
45 Correct 332 ms 5616 KB Output is correct
46 Correct 255 ms 5616 KB Output is correct
47 Correct 41 ms 5616 KB Output is correct
48 Correct 38 ms 5616 KB Output is correct
49 Correct 38 ms 5616 KB Output is correct
50 Correct 26 ms 5616 KB Output is correct
51 Correct 95 ms 5616 KB Output is correct
52 Correct 116 ms 5616 KB Output is correct
53 Correct 48 ms 5616 KB Output is correct
54 Correct 7 ms 5616 KB Output is correct
55 Correct 11 ms 5616 KB Output is correct
56 Correct 46 ms 5616 KB Output is correct
57 Correct 7 ms 5616 KB Output is correct
58 Correct 32 ms 5616 KB Output is correct
59 Correct 36 ms 5616 KB Output is correct
60 Correct 40 ms 5616 KB Output is correct
61 Correct 34 ms 5616 KB Output is correct
62 Correct 195 ms 5768 KB Output is correct
63 Execution timed out 1053 ms 6696 KB Time limit exceeded
64 Halted 0 ms 0 KB -