Submission #41449

# Submission time Handle Problem Language Result Execution time Memory
41449 2018-02-17T08:56:16 Z Nurlykhan Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 3820 KB
#include <bits/stdc++.h>

#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define vec vector<int>
#define dead not_bad

#define left not_right
#define y1 what

using namespace std;

const int N = (int) 3e4 + 10;
const int M = (int) 2e4 + 10;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const double PI = 3.14159265359;
const double EPS = (double) 1e-9;

int nx[8] = {-1, -2, -2, -1, 1, 1, 2, 2};
int ny[8] = {-2, -1, 1, 2, -2, 2, -1, 1};

int n, m;
int b[N], p[N];
int d[N];
bool u[N];
set<int> v[N];

int main() {
  #define fn "teams"
  #ifdef witch
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #else
      //freopen(fn".in", "r", stdin);
      //freopen(fn".out", "w", stdout);
  #endif
  cin >> n >> m;
  for (int i = 0; i < N; i++) {
    d[i] = INF;
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i] >> p[i];
    v[b[i]].insert(i);
  }
  if (n <= 2000) {
    d[b[0]] = 0;
    for (int iter = 1; iter < n; iter++) {
      int id = -1;
      for (int i = 0; i < n; i++) {
        if (!u[i] && (id == -1 || d[id] > d[i])) {
          id = i;
        }
      }
      if (id == -1 || d[id] == INF) 
        break;
      if (id == b[1]) 
        break;
      u[id] = 1;

      for (auto it : v[id]) {
        for (int x = id, step = 0; x < n; x += p[it], ++step) {
          if (d[id] + step < d[x]) {
            d[x] = d[id] + step;
          }
        }
        for (int x = id, step = 0; x >= 0; x -= p[it], ++step) {
          if (d[id] + step < d[x]) {
            d[x] = d[id] + step;
          }
        }
      }
    }
    if (d[b[1]] == INF) d[b[1]] = -1;
    cout << d[b[1]];
    return 0;
  }
  d[0] = 0;
  for (int iter = 1; iter < m; iter++) {
    int id = -1;
    for (int i = 0; i < m; i++) {
      if (!u[i] && (id == -1 || d[id] > d[i])) {
        id = i;
      }
    }
    if (id == -1 || d[id] == INF) 
      break;
    if (id == 1) 
      break;
    u[id] = 1;
    v[b[id]].erase(id);
    for (int x = b[id], step = 0; x < n; x += p[id], ++step) {
      for (auto it : v[x]) {
        if (d[id] + step < d[it]) {
          d[it] = d[id] + step;
        }
      }
    }
    for (int x = b[id], step = 0; x >= 0; x -= p[id], ++step) {
      for (auto it : v[x]) {
        if (d[id] + step < d[it]) {
          d[it] = d[id] + step;
        }
      }
    }
  }
  if (d[1] == INF)
    d[1] = -1;
  cout << d[1];
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1784 KB Output is correct
2 Correct 3 ms 1916 KB Output is correct
3 Correct 2 ms 1960 KB Output is correct
4 Correct 2 ms 1960 KB Output is correct
5 Correct 3 ms 1960 KB Output is correct
6 Correct 3 ms 2104 KB Output is correct
7 Correct 3 ms 2104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2104 KB Output is correct
2 Correct 3 ms 2104 KB Output is correct
3 Correct 2 ms 2104 KB Output is correct
4 Correct 3 ms 2104 KB Output is correct
5 Correct 3 ms 2104 KB Output is correct
6 Correct 3 ms 2104 KB Output is correct
7 Correct 2 ms 2104 KB Output is correct
8 Correct 3 ms 2104 KB Output is correct
9 Correct 2 ms 2104 KB Output is correct
10 Correct 4 ms 2112 KB Output is correct
11 Correct 4 ms 2112 KB Output is correct
12 Correct 4 ms 2112 KB Output is correct
13 Correct 4 ms 2240 KB Output is correct
14 Correct 3 ms 2240 KB Output is correct
15 Correct 3 ms 2240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2240 KB Output is correct
2 Correct 2 ms 2240 KB Output is correct
3 Correct 3 ms 2240 KB Output is correct
4 Correct 3 ms 2240 KB Output is correct
5 Correct 3 ms 2240 KB Output is correct
6 Correct 3 ms 2240 KB Output is correct
7 Correct 3 ms 2240 KB Output is correct
8 Correct 3 ms 2240 KB Output is correct
9 Correct 2 ms 2240 KB Output is correct
10 Correct 3 ms 2240 KB Output is correct
11 Correct 4 ms 2240 KB Output is correct
12 Correct 4 ms 2240 KB Output is correct
13 Correct 4 ms 2240 KB Output is correct
14 Correct 4 ms 2240 KB Output is correct
15 Correct 4 ms 2240 KB Output is correct
16 Correct 3 ms 2240 KB Output is correct
17 Correct 4 ms 2240 KB Output is correct
18 Correct 3 ms 2240 KB Output is correct
19 Correct 3 ms 2240 KB Output is correct
20 Correct 17 ms 2240 KB Output is correct
21 Correct 3 ms 2240 KB Output is correct
22 Correct 3 ms 2240 KB Output is correct
23 Correct 8 ms 2240 KB Output is correct
24 Correct 12 ms 2240 KB Output is correct
25 Correct 6 ms 2240 KB Output is correct
26 Correct 11 ms 2240 KB Output is correct
27 Correct 12 ms 2240 KB Output is correct
28 Correct 12 ms 2256 KB Output is correct
29 Correct 12 ms 2284 KB Output is correct
30 Correct 11 ms 2284 KB Output is correct
31 Correct 11 ms 2284 KB Output is correct
32 Correct 11 ms 2284 KB Output is correct
33 Correct 12 ms 2284 KB Output is correct
34 Correct 12 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 3 ms 2284 KB Output is correct
3 Correct 2 ms 2284 KB Output is correct
4 Correct 3 ms 2284 KB Output is correct
5 Correct 2 ms 2284 KB Output is correct
6 Correct 2 ms 2284 KB Output is correct
7 Correct 3 ms 2284 KB Output is correct
8 Correct 3 ms 2284 KB Output is correct
9 Correct 3 ms 2284 KB Output is correct
10 Correct 3 ms 2284 KB Output is correct
11 Correct 5 ms 2284 KB Output is correct
12 Correct 5 ms 2284 KB Output is correct
13 Correct 4 ms 2284 KB Output is correct
14 Correct 4 ms 2284 KB Output is correct
15 Correct 4 ms 2284 KB Output is correct
16 Correct 3 ms 2284 KB Output is correct
17 Correct 5 ms 2284 KB Output is correct
18 Correct 3 ms 2284 KB Output is correct
19 Correct 3 ms 2284 KB Output is correct
20 Correct 15 ms 2284 KB Output is correct
21 Correct 5 ms 2284 KB Output is correct
22 Correct 4 ms 2284 KB Output is correct
23 Correct 9 ms 2284 KB Output is correct
24 Correct 11 ms 2284 KB Output is correct
25 Correct 6 ms 2284 KB Output is correct
26 Correct 11 ms 2284 KB Output is correct
27 Correct 12 ms 2284 KB Output is correct
28 Correct 12 ms 2284 KB Output is correct
29 Correct 11 ms 2284 KB Output is correct
30 Correct 11 ms 2284 KB Output is correct
31 Correct 13 ms 2284 KB Output is correct
32 Correct 11 ms 2284 KB Output is correct
33 Correct 12 ms 2284 KB Output is correct
34 Correct 13 ms 2284 KB Output is correct
35 Correct 29 ms 3436 KB Output is correct
36 Correct 6 ms 3436 KB Output is correct
37 Correct 23 ms 3436 KB Output is correct
38 Correct 29 ms 3692 KB Output is correct
39 Correct 26 ms 3692 KB Output is correct
40 Correct 26 ms 3692 KB Output is correct
41 Correct 28 ms 3692 KB Output is correct
42 Correct 31 ms 3692 KB Output is correct
43 Correct 33 ms 3692 KB Output is correct
44 Correct 84 ms 3696 KB Output is correct
45 Correct 35 ms 3696 KB Output is correct
46 Correct 35 ms 3696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3696 KB Output is correct
2 Correct 3 ms 3696 KB Output is correct
3 Correct 3 ms 3696 KB Output is correct
4 Correct 3 ms 3696 KB Output is correct
5 Correct 3 ms 3696 KB Output is correct
6 Correct 3 ms 3696 KB Output is correct
7 Correct 3 ms 3696 KB Output is correct
8 Correct 3 ms 3696 KB Output is correct
9 Correct 3 ms 3696 KB Output is correct
10 Correct 4 ms 3696 KB Output is correct
11 Correct 6 ms 3696 KB Output is correct
12 Correct 4 ms 3696 KB Output is correct
13 Correct 5 ms 3696 KB Output is correct
14 Correct 4 ms 3696 KB Output is correct
15 Correct 4 ms 3696 KB Output is correct
16 Correct 3 ms 3696 KB Output is correct
17 Correct 4 ms 3696 KB Output is correct
18 Correct 3 ms 3696 KB Output is correct
19 Correct 3 ms 3696 KB Output is correct
20 Correct 16 ms 3696 KB Output is correct
21 Correct 5 ms 3696 KB Output is correct
22 Correct 4 ms 3696 KB Output is correct
23 Correct 9 ms 3696 KB Output is correct
24 Correct 13 ms 3696 KB Output is correct
25 Correct 7 ms 3696 KB Output is correct
26 Correct 12 ms 3696 KB Output is correct
27 Correct 13 ms 3696 KB Output is correct
28 Correct 14 ms 3696 KB Output is correct
29 Correct 11 ms 3696 KB Output is correct
30 Correct 11 ms 3696 KB Output is correct
31 Correct 12 ms 3696 KB Output is correct
32 Correct 11 ms 3696 KB Output is correct
33 Correct 13 ms 3696 KB Output is correct
34 Correct 12 ms 3696 KB Output is correct
35 Correct 35 ms 3696 KB Output is correct
36 Correct 9 ms 3696 KB Output is correct
37 Correct 23 ms 3696 KB Output is correct
38 Correct 31 ms 3696 KB Output is correct
39 Correct 28 ms 3716 KB Output is correct
40 Correct 32 ms 3716 KB Output is correct
41 Correct 29 ms 3716 KB Output is correct
42 Correct 36 ms 3716 KB Output is correct
43 Correct 33 ms 3716 KB Output is correct
44 Correct 89 ms 3820 KB Output is correct
45 Correct 40 ms 3820 KB Output is correct
46 Correct 40 ms 3820 KB Output is correct
47 Correct 286 ms 3820 KB Output is correct
48 Correct 20 ms 3820 KB Output is correct
49 Correct 19 ms 3820 KB Output is correct
50 Correct 14 ms 3820 KB Output is correct
51 Execution timed out 1060 ms 3820 KB Time limit exceeded
52 Halted 0 ms 0 KB -