Submission #60495

# Submission time Handle Problem Language Result Execution time Memory
60495 2018-07-24T09:09:43 Z dukati8 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 7292 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<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);
  }
  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.front();
    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 3 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 3 ms 484 KB Output is correct
7 Correct 2 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 564 KB Output is correct
2 Correct 3 ms 564 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 3 ms 564 KB Output is correct
6 Correct 3 ms 564 KB Output is correct
7 Correct 3 ms 564 KB Output is correct
8 Correct 3 ms 568 KB Output is correct
9 Correct 3 ms 568 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 4 ms 748 KB Output is correct
12 Correct 4 ms 748 KB Output is correct
13 Correct 5 ms 748 KB Output is correct
14 Correct 6 ms 876 KB Output is correct
15 Correct 6 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1004 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 3 ms 1004 KB Output is correct
4 Correct 3 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 4 ms 1004 KB Output is correct
7 Correct 3 ms 1004 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 3 ms 1004 KB Output is correct
10 Correct 3 ms 1004 KB Output is correct
11 Correct 4 ms 1004 KB Output is correct
12 Correct 4 ms 1004 KB Output is correct
13 Correct 4 ms 1004 KB Output is correct
14 Correct 6 ms 1004 KB Output is correct
15 Correct 6 ms 1004 KB Output is correct
16 Correct 3 ms 1004 KB Output is correct
17 Correct 5 ms 1004 KB Output is correct
18 Correct 4 ms 1004 KB Output is correct
19 Correct 3 ms 1004 KB Output is correct
20 Correct 5 ms 1004 KB Output is correct
21 Correct 4 ms 1004 KB Output is correct
22 Correct 3 ms 1004 KB Output is correct
23 Correct 5 ms 1004 KB Output is correct
24 Correct 5 ms 1004 KB Output is correct
25 Correct 6 ms 1004 KB Output is correct
26 Correct 5 ms 1004 KB Output is correct
27 Correct 6 ms 1004 KB Output is correct
28 Correct 7 ms 1004 KB Output is correct
29 Correct 10 ms 1004 KB Output is correct
30 Correct 6 ms 1004 KB Output is correct
31 Correct 7 ms 1004 KB Output is correct
32 Correct 7 ms 1004 KB Output is correct
33 Correct 19 ms 1020 KB Output is correct
34 Correct 11 ms 1020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1020 KB Output is correct
2 Correct 3 ms 1020 KB Output is correct
3 Correct 2 ms 1020 KB Output is correct
4 Correct 3 ms 1020 KB Output is correct
5 Correct 2 ms 1020 KB Output is correct
6 Correct 3 ms 1020 KB Output is correct
7 Correct 3 ms 1020 KB Output is correct
8 Correct 3 ms 1020 KB Output is correct
9 Correct 3 ms 1020 KB Output is correct
10 Correct 3 ms 1020 KB Output is correct
11 Correct 4 ms 1020 KB Output is correct
12 Correct 4 ms 1020 KB Output is correct
13 Correct 3 ms 1020 KB Output is correct
14 Correct 7 ms 1020 KB Output is correct
15 Correct 6 ms 1020 KB Output is correct
16 Correct 4 ms 1020 KB Output is correct
17 Correct 4 ms 1020 KB Output is correct
18 Correct 4 ms 1020 KB Output is correct
19 Correct 4 ms 1020 KB Output is correct
20 Correct 6 ms 1020 KB Output is correct
21 Correct 3 ms 1020 KB Output is correct
22 Correct 3 ms 1020 KB Output is correct
23 Correct 6 ms 1020 KB Output is correct
24 Correct 6 ms 1020 KB Output is correct
25 Correct 5 ms 1020 KB Output is correct
26 Correct 4 ms 1020 KB Output is correct
27 Correct 5 ms 1020 KB Output is correct
28 Correct 6 ms 1020 KB Output is correct
29 Correct 9 ms 1020 KB Output is correct
30 Correct 5 ms 1020 KB Output is correct
31 Correct 8 ms 1020 KB Output is correct
32 Correct 6 ms 1020 KB Output is correct
33 Correct 25 ms 1020 KB Output is correct
34 Correct 16 ms 1020 KB Output is correct
35 Correct 64 ms 4348 KB Output is correct
36 Correct 7 ms 4348 KB Output is correct
37 Correct 40 ms 4348 KB Output is correct
38 Correct 46 ms 5116 KB Output is correct
39 Correct 52 ms 5116 KB Output is correct
40 Correct 70 ms 5116 KB Output is correct
41 Correct 62 ms 5116 KB Output is correct
42 Correct 24 ms 5116 KB Output is correct
43 Correct 34 ms 5116 KB Output is correct
44 Correct 24 ms 5116 KB Output is correct
45 Correct 115 ms 5628 KB Output is correct
46 Correct 95 ms 5676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5676 KB Output is correct
2 Correct 2 ms 5676 KB Output is correct
3 Correct 3 ms 5676 KB Output is correct
4 Correct 3 ms 5676 KB Output is correct
5 Correct 3 ms 5676 KB Output is correct
6 Correct 3 ms 5676 KB Output is correct
7 Correct 3 ms 5676 KB Output is correct
8 Correct 2 ms 5676 KB Output is correct
9 Correct 2 ms 5676 KB Output is correct
10 Correct 3 ms 5676 KB Output is correct
11 Correct 4 ms 5676 KB Output is correct
12 Correct 4 ms 5676 KB Output is correct
13 Correct 4 ms 5676 KB Output is correct
14 Correct 6 ms 5676 KB Output is correct
15 Correct 7 ms 5676 KB Output is correct
16 Correct 3 ms 5676 KB Output is correct
17 Correct 5 ms 5676 KB Output is correct
18 Correct 4 ms 5676 KB Output is correct
19 Correct 3 ms 5676 KB Output is correct
20 Correct 4 ms 5676 KB Output is correct
21 Correct 3 ms 5676 KB Output is correct
22 Correct 5 ms 5676 KB Output is correct
23 Correct 4 ms 5676 KB Output is correct
24 Correct 6 ms 5676 KB Output is correct
25 Correct 7 ms 5676 KB Output is correct
26 Correct 5 ms 5676 KB Output is correct
27 Correct 5 ms 5676 KB Output is correct
28 Correct 7 ms 5676 KB Output is correct
29 Correct 12 ms 5676 KB Output is correct
30 Correct 5 ms 5676 KB Output is correct
31 Correct 7 ms 5676 KB Output is correct
32 Correct 6 ms 5676 KB Output is correct
33 Correct 17 ms 5676 KB Output is correct
34 Correct 12 ms 5676 KB Output is correct
35 Correct 50 ms 5676 KB Output is correct
36 Correct 8 ms 5676 KB Output is correct
37 Correct 32 ms 5676 KB Output is correct
38 Correct 59 ms 5676 KB Output is correct
39 Correct 41 ms 5676 KB Output is correct
40 Correct 66 ms 5676 KB Output is correct
41 Correct 53 ms 5676 KB Output is correct
42 Correct 23 ms 5676 KB Output is correct
43 Correct 22 ms 5676 KB Output is correct
44 Correct 23 ms 5676 KB Output is correct
45 Correct 110 ms 5788 KB Output is correct
46 Correct 88 ms 5788 KB Output is correct
47 Correct 53 ms 5788 KB Output is correct
48 Correct 25 ms 5788 KB Output is correct
49 Correct 25 ms 5788 KB Output is correct
50 Correct 23 ms 5788 KB Output is correct
51 Correct 53 ms 5788 KB Output is correct
52 Correct 56 ms 5788 KB Output is correct
53 Correct 53 ms 5788 KB Output is correct
54 Correct 7 ms 5788 KB Output is correct
55 Correct 7 ms 5788 KB Output is correct
56 Correct 44 ms 5788 KB Output is correct
57 Correct 7 ms 5788 KB Output is correct
58 Correct 29 ms 5788 KB Output is correct
59 Correct 39 ms 5788 KB Output is correct
60 Correct 31 ms 5788 KB Output is correct
61 Correct 33 ms 5788 KB Output is correct
62 Correct 187 ms 5788 KB Output is correct
63 Correct 410 ms 5788 KB Output is correct
64 Correct 790 ms 5788 KB Output is correct
65 Correct 902 ms 5788 KB Output is correct
66 Execution timed out 1061 ms 7292 KB Time limit exceeded
67 Halted 0 ms 0 KB -