Submission #60509

# Submission time Handle Problem Language Result Execution time Memory
60509 2018-07-24T09:28:39 Z dukati8 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
664 ms 7212 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()) {
    int num,pos,p;
    num=-order.front()[0];
    pos=order.front()[1];
    p=order.front()[2];
    bool left = order.front()[3]==1;
    order.pop();

    int next;
    if (left) next=pos+p;
    else next=pos-p;
    if (next>=0 && next<n) {
      if (next==stop) {dp[next]=min(num+1,dp[next]); break;}
      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,left});
    }
  }
  if (dp[stop] == 1000000000) cout << -1 << endl;
  else cout << dp[stop]<< endl;

}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 3 ms 392 KB Output is correct
5 Correct 3 ms 440 KB Output is correct
6 Correct 3 ms 440 KB Output is correct
7 Correct 3 ms 516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 516 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 3 ms 612 KB Output is correct
7 Correct 3 ms 612 KB Output is correct
8 Correct 3 ms 612 KB Output is correct
9 Correct 2 ms 612 KB Output is correct
10 Correct 3 ms 612 KB Output is correct
11 Correct 4 ms 612 KB Output is correct
12 Correct 4 ms 612 KB Output is correct
13 Correct 4 ms 612 KB Output is correct
14 Correct 5 ms 868 KB Output is correct
15 Correct 4 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 868 KB Output is correct
2 Correct 2 ms 868 KB Output is correct
3 Correct 2 ms 868 KB Output is correct
4 Correct 2 ms 868 KB Output is correct
5 Correct 3 ms 868 KB Output is correct
6 Correct 3 ms 868 KB Output is correct
7 Correct 2 ms 868 KB Output is correct
8 Correct 2 ms 868 KB Output is correct
9 Correct 2 ms 868 KB Output is correct
10 Correct 4 ms 868 KB Output is correct
11 Correct 5 ms 868 KB Output is correct
12 Correct 3 ms 868 KB Output is correct
13 Correct 4 ms 868 KB Output is correct
14 Correct 6 ms 984 KB Output is correct
15 Correct 6 ms 984 KB Output is correct
16 Correct 4 ms 984 KB Output is correct
17 Correct 5 ms 984 KB Output is correct
18 Correct 4 ms 984 KB Output is correct
19 Correct 4 ms 984 KB Output is correct
20 Correct 5 ms 984 KB Output is correct
21 Correct 4 ms 984 KB Output is correct
22 Correct 3 ms 984 KB Output is correct
23 Correct 4 ms 984 KB Output is correct
24 Correct 4 ms 984 KB Output is correct
25 Correct 6 ms 984 KB Output is correct
26 Correct 5 ms 984 KB Output is correct
27 Correct 5 ms 984 KB Output is correct
28 Correct 5 ms 984 KB Output is correct
29 Correct 7 ms 984 KB Output is correct
30 Correct 4 ms 984 KB Output is correct
31 Correct 5 ms 984 KB Output is correct
32 Correct 4 ms 984 KB Output is correct
33 Correct 14 ms 996 KB Output is correct
34 Correct 8 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1132 KB Output is correct
2 Correct 3 ms 1132 KB Output is correct
3 Correct 3 ms 1132 KB Output is correct
4 Correct 3 ms 1132 KB Output is correct
5 Correct 3 ms 1132 KB Output is correct
6 Correct 3 ms 1132 KB Output is correct
7 Correct 3 ms 1132 KB Output is correct
8 Correct 3 ms 1132 KB Output is correct
9 Correct 3 ms 1132 KB Output is correct
10 Correct 3 ms 1132 KB Output is correct
11 Correct 1 ms 1132 KB Output is correct
12 Correct 5 ms 1132 KB Output is correct
13 Correct 5 ms 1132 KB Output is correct
14 Correct 6 ms 1132 KB Output is correct
15 Correct 4 ms 1132 KB Output is correct
16 Correct 3 ms 1132 KB Output is correct
17 Correct 3 ms 1132 KB Output is correct
18 Correct 6 ms 1132 KB Output is correct
19 Correct 3 ms 1132 KB Output is correct
20 Correct 4 ms 1132 KB Output is correct
21 Correct 4 ms 1132 KB Output is correct
22 Correct 3 ms 1132 KB Output is correct
23 Correct 5 ms 1132 KB Output is correct
24 Correct 5 ms 1132 KB Output is correct
25 Correct 4 ms 1132 KB Output is correct
26 Correct 4 ms 1132 KB Output is correct
27 Correct 5 ms 1132 KB Output is correct
28 Correct 8 ms 1132 KB Output is correct
29 Correct 7 ms 1132 KB Output is correct
30 Correct 4 ms 1132 KB Output is correct
31 Correct 7 ms 1132 KB Output is correct
32 Correct 5 ms 1132 KB Output is correct
33 Correct 14 ms 1132 KB Output is correct
34 Correct 9 ms 1132 KB Output is correct
35 Correct 48 ms 4348 KB Output is correct
36 Correct 7 ms 4348 KB Output is correct
37 Correct 30 ms 4348 KB Output is correct
38 Correct 72 ms 4348 KB Output is correct
39 Correct 43 ms 4348 KB Output is correct
40 Correct 42 ms 4348 KB Output is correct
41 Correct 48 ms 4860 KB Output is correct
42 Correct 21 ms 4860 KB Output is correct
43 Correct 21 ms 4860 KB Output is correct
44 Correct 21 ms 4860 KB Output is correct
45 Correct 84 ms 5628 KB Output is correct
46 Correct 74 ms 5628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5628 KB Output is correct
2 Correct 2 ms 5628 KB Output is correct
3 Correct 3 ms 5628 KB Output is correct
4 Correct 2 ms 5628 KB Output is correct
5 Correct 2 ms 5628 KB Output is correct
6 Correct 2 ms 5628 KB Output is correct
7 Correct 3 ms 5628 KB Output is correct
8 Correct 3 ms 5628 KB Output is correct
9 Correct 3 ms 5628 KB Output is correct
10 Correct 4 ms 5628 KB Output is correct
11 Correct 5 ms 5628 KB Output is correct
12 Correct 3 ms 5628 KB Output is correct
13 Correct 4 ms 5628 KB Output is correct
14 Correct 6 ms 5628 KB Output is correct
15 Correct 4 ms 5628 KB Output is correct
16 Correct 3 ms 5628 KB Output is correct
17 Correct 5 ms 5628 KB Output is correct
18 Correct 5 ms 5628 KB Output is correct
19 Correct 3 ms 5628 KB Output is correct
20 Correct 4 ms 5628 KB Output is correct
21 Correct 4 ms 5628 KB Output is correct
22 Correct 3 ms 5628 KB Output is correct
23 Correct 4 ms 5628 KB Output is correct
24 Correct 8 ms 5628 KB Output is correct
25 Correct 5 ms 5628 KB Output is correct
26 Correct 6 ms 5628 KB Output is correct
27 Correct 4 ms 5628 KB Output is correct
28 Correct 6 ms 5628 KB Output is correct
29 Correct 9 ms 5628 KB Output is correct
30 Correct 4 ms 5628 KB Output is correct
31 Correct 5 ms 5628 KB Output is correct
32 Correct 4 ms 5628 KB Output is correct
33 Correct 11 ms 5628 KB Output is correct
34 Correct 12 ms 5628 KB Output is correct
35 Correct 63 ms 5628 KB Output is correct
36 Correct 6 ms 5628 KB Output is correct
37 Correct 25 ms 5628 KB Output is correct
38 Correct 63 ms 5628 KB Output is correct
39 Correct 44 ms 5628 KB Output is correct
40 Correct 47 ms 5628 KB Output is correct
41 Correct 58 ms 5628 KB Output is correct
42 Correct 21 ms 5628 KB Output is correct
43 Correct 21 ms 5628 KB Output is correct
44 Correct 20 ms 5628 KB Output is correct
45 Correct 137 ms 5760 KB Output is correct
46 Correct 64 ms 5760 KB Output is correct
47 Correct 28 ms 5760 KB Output is correct
48 Correct 27 ms 5760 KB Output is correct
49 Correct 36 ms 5760 KB Output is correct
50 Correct 22 ms 5760 KB Output is correct
51 Correct 54 ms 5760 KB Output is correct
52 Correct 74 ms 5760 KB Output is correct
53 Correct 46 ms 5760 KB Output is correct
54 Correct 5 ms 5760 KB Output is correct
55 Correct 5 ms 5760 KB Output is correct
56 Correct 33 ms 5760 KB Output is correct
57 Correct 7 ms 5760 KB Output is correct
58 Correct 21 ms 5760 KB Output is correct
59 Correct 45 ms 5760 KB Output is correct
60 Correct 26 ms 5760 KB Output is correct
61 Correct 42 ms 5760 KB Output is correct
62 Correct 67 ms 5760 KB Output is correct
63 Correct 241 ms 5760 KB Output is correct
64 Correct 276 ms 5760 KB Output is correct
65 Correct 384 ms 5760 KB Output is correct
66 Correct 664 ms 7036 KB Output is correct
67 Correct 233 ms 7212 KB Output is correct