답안 #41433

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41433 2018-02-17T08:27:17 Z Nurlykhan Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 33772 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];
ll d[N];
vector<pii> 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 < m; i++) {
    cin >> b[i] >> p[i];
    d[i] = LINF;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i == j) 
        continue;
      int e = INF;
      if ((b[j] - b[i]) % p[i] == 0) {
        e = min(e, abs(b[j] - b[i]) / p[i]);
      }
      if (e < INF) {
      //  cout << i << ' ' << j << ' ' << e << endl;
        v[i].pb(mp(j, e));
      }
    }
  }
  set<pair<ll, int> > st;
  st.insert(mp(0, 0));
  d[0] = 0;
  while (!st.empty()) {
    int fr = st.begin() -> s;
    st.erase(st.begin());
    for (auto it : v[fr]) {
      if (d[fr] + it.s < d[it.f]) {
        st.erase(mp(d[it.f], it.f));
        d[it.f] = d[fr] + it.s;
        st.insert(mp(d[it.f], it.f));
      }
    }
  }
  if (d[1] == LINF)
    d[1] = -1;
  cout << d[1];
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1016 KB Output is correct
2 Correct 2 ms 1120 KB Output is correct
3 Correct 2 ms 1192 KB Output is correct
4 Correct 2 ms 1192 KB Output is correct
5 Correct 2 ms 1192 KB Output is correct
6 Correct 2 ms 1192 KB Output is correct
7 Correct 2 ms 1220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1224 KB Output is correct
2 Correct 2 ms 1224 KB Output is correct
3 Correct 3 ms 1224 KB Output is correct
4 Correct 2 ms 1244 KB Output is correct
5 Correct 2 ms 1248 KB Output is correct
6 Correct 2 ms 1248 KB Output is correct
7 Correct 2 ms 1248 KB Output is correct
8 Correct 2 ms 1260 KB Output is correct
9 Correct 3 ms 1316 KB Output is correct
10 Correct 5 ms 1444 KB Output is correct
11 Correct 35 ms 3596 KB Output is correct
12 Correct 86 ms 33260 KB Output is correct
13 Correct 88 ms 33772 KB Output is correct
14 Correct 29 ms 33772 KB Output is correct
15 Correct 28 ms 33772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 33772 KB Output is correct
2 Correct 2 ms 33772 KB Output is correct
3 Correct 2 ms 33772 KB Output is correct
4 Correct 2 ms 33772 KB Output is correct
5 Correct 2 ms 33772 KB Output is correct
6 Correct 2 ms 33772 KB Output is correct
7 Correct 2 ms 33772 KB Output is correct
8 Correct 2 ms 33772 KB Output is correct
9 Correct 2 ms 33772 KB Output is correct
10 Correct 5 ms 33772 KB Output is correct
11 Correct 42 ms 33772 KB Output is correct
12 Correct 85 ms 33772 KB Output is correct
13 Correct 106 ms 33772 KB Output is correct
14 Correct 28 ms 33772 KB Output is correct
15 Correct 28 ms 33772 KB Output is correct
16 Correct 7 ms 33772 KB Output is correct
17 Correct 28 ms 33772 KB Output is correct
18 Correct 7 ms 33772 KB Output is correct
19 Correct 4 ms 33772 KB Output is correct
20 Correct 87 ms 33772 KB Output is correct
21 Correct 9 ms 33772 KB Output is correct
22 Correct 5 ms 33772 KB Output is correct
23 Correct 8 ms 33772 KB Output is correct
24 Correct 21 ms 33772 KB Output is correct
25 Correct 24 ms 33772 KB Output is correct
26 Correct 81 ms 33772 KB Output is correct
27 Correct 82 ms 33772 KB Output is correct
28 Correct 22 ms 33772 KB Output is correct
29 Correct 6 ms 33772 KB Output is correct
30 Correct 2 ms 33772 KB Output is correct
31 Correct 4 ms 33772 KB Output is correct
32 Correct 4 ms 33772 KB Output is correct
33 Correct 39 ms 33772 KB Output is correct
34 Correct 35 ms 33772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 33772 KB Output is correct
2 Correct 2 ms 33772 KB Output is correct
3 Correct 2 ms 33772 KB Output is correct
4 Correct 2 ms 33772 KB Output is correct
5 Correct 3 ms 33772 KB Output is correct
6 Correct 2 ms 33772 KB Output is correct
7 Correct 2 ms 33772 KB Output is correct
8 Correct 2 ms 33772 KB Output is correct
9 Correct 2 ms 33772 KB Output is correct
10 Correct 3 ms 33772 KB Output is correct
11 Correct 29 ms 33772 KB Output is correct
12 Correct 86 ms 33772 KB Output is correct
13 Correct 111 ms 33772 KB Output is correct
14 Correct 28 ms 33772 KB Output is correct
15 Correct 30 ms 33772 KB Output is correct
16 Correct 7 ms 33772 KB Output is correct
17 Correct 21 ms 33772 KB Output is correct
18 Correct 8 ms 33772 KB Output is correct
19 Correct 4 ms 33772 KB Output is correct
20 Correct 98 ms 33772 KB Output is correct
21 Correct 9 ms 33772 KB Output is correct
22 Correct 5 ms 33772 KB Output is correct
23 Correct 7 ms 33772 KB Output is correct
24 Correct 21 ms 33772 KB Output is correct
25 Correct 23 ms 33772 KB Output is correct
26 Correct 81 ms 33772 KB Output is correct
27 Correct 82 ms 33772 KB Output is correct
28 Correct 23 ms 33772 KB Output is correct
29 Correct 6 ms 33772 KB Output is correct
30 Correct 2 ms 33772 KB Output is correct
31 Correct 4 ms 33772 KB Output is correct
32 Correct 4 ms 33772 KB Output is correct
33 Correct 31 ms 33772 KB Output is correct
34 Correct 28 ms 33772 KB Output is correct
35 Execution timed out 1072 ms 33772 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 33772 KB Output is correct
2 Correct 2 ms 33772 KB Output is correct
3 Correct 2 ms 33772 KB Output is correct
4 Correct 2 ms 33772 KB Output is correct
5 Correct 3 ms 33772 KB Output is correct
6 Correct 2 ms 33772 KB Output is correct
7 Correct 2 ms 33772 KB Output is correct
8 Correct 2 ms 33772 KB Output is correct
9 Correct 2 ms 33772 KB Output is correct
10 Correct 5 ms 33772 KB Output is correct
11 Correct 30 ms 33772 KB Output is correct
12 Correct 102 ms 33772 KB Output is correct
13 Correct 91 ms 33772 KB Output is correct
14 Correct 28 ms 33772 KB Output is correct
15 Correct 28 ms 33772 KB Output is correct
16 Correct 7 ms 33772 KB Output is correct
17 Correct 22 ms 33772 KB Output is correct
18 Correct 7 ms 33772 KB Output is correct
19 Correct 4 ms 33772 KB Output is correct
20 Correct 91 ms 33772 KB Output is correct
21 Correct 11 ms 33772 KB Output is correct
22 Correct 5 ms 33772 KB Output is correct
23 Correct 7 ms 33772 KB Output is correct
24 Correct 21 ms 33772 KB Output is correct
25 Correct 26 ms 33772 KB Output is correct
26 Correct 80 ms 33772 KB Output is correct
27 Correct 82 ms 33772 KB Output is correct
28 Correct 22 ms 33772 KB Output is correct
29 Correct 6 ms 33772 KB Output is correct
30 Correct 3 ms 33772 KB Output is correct
31 Correct 5 ms 33772 KB Output is correct
32 Correct 5 ms 33772 KB Output is correct
33 Correct 28 ms 33772 KB Output is correct
34 Correct 31 ms 33772 KB Output is correct
35 Execution timed out 1075 ms 33772 KB Time limit exceeded
36 Halted 0 ms 0 KB -