답안 #78352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
78352 2018-10-03T18:45:09 Z xiaowuc1 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
226 ms 76136 KB
#include <bits/stdc++.h>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);

ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, ll> pill;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<vector<ll>> matrix;

int dp[30001];
set<int> amts[30001];
int src, dest;
int n;

vector<pii> edges[30001];

void solve() {
  priority_queue<pii> q;
  q.push(pii(0, src));
  while(!q.empty()) {
    pii curr = q.top();
    q.pop();
    if(curr.second == dest) {
      printf("%d\n", dp[curr.second]);
      return;
    }
    if(dp[curr.second] != -curr.first) continue;
    for(pii out: edges[curr.second]) {
      int nd = out.first;
      int nw = dp[curr.second] + out.second;
      if(nw < dp[nd]) {
        dp[nd] = nw;
        q.push(pii(-dp[nd], nd));
      }
    }
  }
  printf("-1\n");
}

void loadGraph() {
  for(int i = 0; i < n; i++) {
    for(int out: amts[i]) {
      for(int dx = 1; i - dx * out >= 0; dx++) {
        edges[i].push_back(pii(i-dx*out, dx));
        if(amts[i-dx*out].count(out)) break;
      }
      for(int dx = 1; i + dx * out < n; dx++) {
        edges[i].push_back(pii(i+dx*out, dx));
        if(amts[i+dx*out].count(out)) break;
      }
    }
  }
}

int main() {
  int m;
  scanf("%d%d", &n, &m);
  for(int i = 0; i < n; i++) {
    dp[i] = 1 << 25;
  }
  for(int i = 0; i < m; i++) {
    int loc, jump;
    scanf("%d %d", &loc, &jump);
    amts[loc].insert(jump);
    if(i == 0) {
      src = loc;
      dp[loc] = 0;
    }
    else if(i == 1) {
      dest = loc;
    }
  }
  loadGraph();
  solve();
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &loc, &jump);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2424 KB Output is correct
2 Correct 4 ms 2460 KB Output is correct
3 Correct 4 ms 2616 KB Output is correct
4 Correct 4 ms 2692 KB Output is correct
5 Correct 4 ms 2692 KB Output is correct
6 Correct 4 ms 2692 KB Output is correct
7 Correct 4 ms 2692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2692 KB Output is correct
2 Correct 4 ms 2692 KB Output is correct
3 Correct 4 ms 2692 KB Output is correct
4 Correct 4 ms 2692 KB Output is correct
5 Correct 4 ms 2692 KB Output is correct
6 Correct 4 ms 2692 KB Output is correct
7 Correct 4 ms 2692 KB Output is correct
8 Correct 4 ms 2692 KB Output is correct
9 Correct 4 ms 2692 KB Output is correct
10 Correct 5 ms 2692 KB Output is correct
11 Correct 5 ms 2812 KB Output is correct
12 Correct 4 ms 2812 KB Output is correct
13 Correct 4 ms 2812 KB Output is correct
14 Correct 5 ms 2856 KB Output is correct
15 Correct 6 ms 3012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3012 KB Output is correct
2 Correct 4 ms 3012 KB Output is correct
3 Correct 4 ms 3012 KB Output is correct
4 Correct 4 ms 3012 KB Output is correct
5 Correct 4 ms 3012 KB Output is correct
6 Correct 4 ms 3012 KB Output is correct
7 Correct 4 ms 3012 KB Output is correct
8 Correct 4 ms 3012 KB Output is correct
9 Correct 4 ms 3012 KB Output is correct
10 Correct 4 ms 3012 KB Output is correct
11 Correct 5 ms 3012 KB Output is correct
12 Correct 4 ms 3012 KB Output is correct
13 Correct 4 ms 3012 KB Output is correct
14 Correct 5 ms 3012 KB Output is correct
15 Correct 5 ms 3096 KB Output is correct
16 Correct 4 ms 3096 KB Output is correct
17 Correct 5 ms 3168 KB Output is correct
18 Correct 5 ms 3168 KB Output is correct
19 Correct 4 ms 3168 KB Output is correct
20 Correct 5 ms 3204 KB Output is correct
21 Correct 6 ms 3204 KB Output is correct
22 Correct 4 ms 3204 KB Output is correct
23 Correct 4 ms 3204 KB Output is correct
24 Correct 5 ms 3300 KB Output is correct
25 Correct 5 ms 3320 KB Output is correct
26 Correct 5 ms 3320 KB Output is correct
27 Correct 5 ms 3320 KB Output is correct
28 Correct 5 ms 3500 KB Output is correct
29 Correct 7 ms 3904 KB Output is correct
30 Correct 5 ms 3904 KB Output is correct
31 Correct 5 ms 3904 KB Output is correct
32 Correct 5 ms 3904 KB Output is correct
33 Correct 8 ms 4564 KB Output is correct
34 Correct 8 ms 4576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4576 KB Output is correct
2 Correct 4 ms 4576 KB Output is correct
3 Correct 5 ms 4576 KB Output is correct
4 Correct 5 ms 4576 KB Output is correct
5 Correct 4 ms 4576 KB Output is correct
6 Correct 4 ms 4576 KB Output is correct
7 Correct 4 ms 4576 KB Output is correct
8 Correct 4 ms 4576 KB Output is correct
9 Correct 4 ms 4576 KB Output is correct
10 Correct 4 ms 4576 KB Output is correct
11 Correct 7 ms 4576 KB Output is correct
12 Correct 5 ms 4576 KB Output is correct
13 Correct 4 ms 4576 KB Output is correct
14 Correct 5 ms 4576 KB Output is correct
15 Correct 5 ms 4576 KB Output is correct
16 Correct 6 ms 4576 KB Output is correct
17 Correct 5 ms 4576 KB Output is correct
18 Correct 5 ms 4576 KB Output is correct
19 Correct 4 ms 4576 KB Output is correct
20 Correct 5 ms 4576 KB Output is correct
21 Correct 5 ms 4576 KB Output is correct
22 Correct 4 ms 4576 KB Output is correct
23 Correct 5 ms 4576 KB Output is correct
24 Correct 7 ms 4576 KB Output is correct
25 Correct 5 ms 4576 KB Output is correct
26 Correct 4 ms 4576 KB Output is correct
27 Correct 5 ms 4576 KB Output is correct
28 Correct 5 ms 4576 KB Output is correct
29 Correct 7 ms 4576 KB Output is correct
30 Correct 5 ms 4576 KB Output is correct
31 Correct 5 ms 4576 KB Output is correct
32 Correct 5 ms 4576 KB Output is correct
33 Correct 9 ms 4868 KB Output is correct
34 Correct 8 ms 4876 KB Output is correct
35 Correct 26 ms 5912 KB Output is correct
36 Correct 7 ms 5912 KB Output is correct
37 Correct 29 ms 6944 KB Output is correct
38 Correct 37 ms 7360 KB Output is correct
39 Correct 32 ms 7624 KB Output is correct
40 Correct 33 ms 7888 KB Output is correct
41 Correct 31 ms 8156 KB Output is correct
42 Correct 10 ms 8156 KB Output is correct
43 Correct 10 ms 8156 KB Output is correct
44 Correct 12 ms 8156 KB Output is correct
45 Correct 45 ms 11600 KB Output is correct
46 Correct 34 ms 11812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11812 KB Output is correct
2 Correct 4 ms 11812 KB Output is correct
3 Correct 4 ms 11812 KB Output is correct
4 Correct 4 ms 11812 KB Output is correct
5 Correct 4 ms 11812 KB Output is correct
6 Correct 4 ms 11812 KB Output is correct
7 Correct 5 ms 11812 KB Output is correct
8 Correct 4 ms 11812 KB Output is correct
9 Correct 4 ms 11812 KB Output is correct
10 Correct 4 ms 11812 KB Output is correct
11 Correct 5 ms 11812 KB Output is correct
12 Correct 4 ms 11812 KB Output is correct
13 Correct 5 ms 11812 KB Output is correct
14 Correct 5 ms 11812 KB Output is correct
15 Correct 5 ms 11812 KB Output is correct
16 Correct 4 ms 11812 KB Output is correct
17 Correct 5 ms 11812 KB Output is correct
18 Correct 5 ms 11812 KB Output is correct
19 Correct 4 ms 11812 KB Output is correct
20 Correct 5 ms 11812 KB Output is correct
21 Correct 4 ms 11812 KB Output is correct
22 Correct 4 ms 11812 KB Output is correct
23 Correct 5 ms 11812 KB Output is correct
24 Correct 6 ms 11812 KB Output is correct
25 Correct 5 ms 11812 KB Output is correct
26 Correct 5 ms 11812 KB Output is correct
27 Correct 5 ms 11812 KB Output is correct
28 Correct 5 ms 11812 KB Output is correct
29 Correct 7 ms 11812 KB Output is correct
30 Correct 5 ms 11812 KB Output is correct
31 Correct 6 ms 11812 KB Output is correct
32 Correct 5 ms 11812 KB Output is correct
33 Correct 9 ms 11812 KB Output is correct
34 Correct 8 ms 11812 KB Output is correct
35 Correct 27 ms 11812 KB Output is correct
36 Correct 7 ms 11812 KB Output is correct
37 Correct 33 ms 11812 KB Output is correct
38 Correct 34 ms 11812 KB Output is correct
39 Correct 33 ms 11812 KB Output is correct
40 Correct 40 ms 11812 KB Output is correct
41 Correct 34 ms 11812 KB Output is correct
42 Correct 10 ms 11812 KB Output is correct
43 Correct 11 ms 11812 KB Output is correct
44 Correct 11 ms 11812 KB Output is correct
45 Correct 38 ms 14440 KB Output is correct
46 Correct 37 ms 14652 KB Output is correct
47 Correct 58 ms 19232 KB Output is correct
48 Correct 26 ms 19232 KB Output is correct
49 Correct 21 ms 19232 KB Output is correct
50 Correct 27 ms 19232 KB Output is correct
51 Correct 41 ms 19232 KB Output is correct
52 Correct 46 ms 19232 KB Output is correct
53 Correct 25 ms 19232 KB Output is correct
54 Correct 6 ms 19232 KB Output is correct
55 Correct 8 ms 19232 KB Output is correct
56 Correct 20 ms 19232 KB Output is correct
57 Correct 23 ms 19936 KB Output is correct
58 Correct 15 ms 19936 KB Output is correct
59 Correct 15 ms 19936 KB Output is correct
60 Correct 16 ms 19936 KB Output is correct
61 Correct 17 ms 19936 KB Output is correct
62 Correct 32 ms 19936 KB Output is correct
63 Correct 89 ms 35308 KB Output is correct
64 Correct 111 ms 38436 KB Output is correct
65 Correct 141 ms 48676 KB Output is correct
66 Correct 226 ms 76040 KB Output is correct
67 Correct 208 ms 76136 KB Output is correct