답안 #242966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242966 2020-06-30T03:30:41 Z neihcr7j Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
222 ms 259684 KB
#include<bits/stdc++.h>

#define oo 1000000000
#define maxm 4000000
#define maxn 50005
#define block 250

using namespace std;
typedef long long ll;

int n, m;
int b[maxn], p[maxn];

vector < pair < int, int > > g[maxm];

int node(int u, int x) {return x * n + u;}

int dist[maxm];

queue < int > L[maxn];

int dijkstra() {
  fill(dist, dist + maxn, oo);
  dist[b[0]] = 0;
  L[0].push(b[0]);

  int M = 1000000;

  for (int i = 0; i <= M; ++i)
    while (!L[i].empty()) {
      int u = L[i].front(); L[i].pop();

      if (u == b[1])
        return i;

      if (dist[u] < i) continue;

      for (auto x : g[u]) {
        int v = x.first, w = x.second;
        if (dist[v] > dist[u] + w && dist[u] + w <= M) {
          dist[v] = dist[u] + w;
          L[dist[v]].push(v);
        }
      }
    }

  return -1;
}

int main(){

  #define TASK "ABC"
	//freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
  ios_base::sync_with_stdio(0);

  cin >> n >> m;

  for (int i = 0; i < m; ++i)
    cin >> b[i] >> p[i];

  for (int j = 1; j <= block; ++j)
    for (int i = j; i < n; ++i)
      g[node(i, j)].push_back({node(i - j, j), 1});

  for (int j = 1; j <= block; ++j)
    for (int i = 0; i + j < n; ++i)
      g[node(i, j)].push_back({node(i + j, j), 1});

  for (int i = 0; i < n; ++i)
    for (int j = 1; j <= block; ++j)
      g[node(i, j)].push_back({i, 0});

  for (int i = 0; i < m; ++i)
    if (p[i] <= block)
      g[b[i]].push_back({node(b[i], p[i]), 0});


  for (int i = 0; i < m; ++i)
    if (p[i] > block)
      for (int j = b[i] % p[i]; j < n; j += p[i])
        if (i != j)
          g[b[i]].push_back({j, abs(j - b[i]) / p[i]});

  //for (int i = 0; i < 10; ++i)
   // for (auto j : g[i])
   //   cerr << i << ' ' << j.first << ' ' << j.second << '\n';
  cout << dijkstra();

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 128120 KB Output is correct
2 Correct 86 ms 128376 KB Output is correct
3 Correct 82 ms 128248 KB Output is correct
4 Runtime error 217 ms 259588 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 128120 KB Output is correct
2 Correct 90 ms 128120 KB Output is correct
3 Correct 82 ms 128120 KB Output is correct
4 Runtime error 214 ms 259684 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 128120 KB Output is correct
2 Correct 80 ms 128248 KB Output is correct
3 Correct 79 ms 128248 KB Output is correct
4 Runtime error 216 ms 259452 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 128120 KB Output is correct
2 Correct 87 ms 128204 KB Output is correct
3 Correct 79 ms 128120 KB Output is correct
4 Runtime error 217 ms 259448 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 128120 KB Output is correct
2 Correct 81 ms 128120 KB Output is correct
3 Correct 83 ms 128248 KB Output is correct
4 Runtime error 222 ms 259452 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -