# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1047386 | 2024-08-07T12:21:26 Z | PanosPask | Circus (Balkan15_CIRCUS) | C++14 | 43 ms | 4052 KB |
#include <bits/stdc++.h> #include "circus.h" #define mp make_pair using namespace std; typedef pair<int, int> pi; int N, M; vector<int> p; // nxt[i]: Next rope in the path from p[i] to M vector<int> nxt; vector<int> minlen; priority_queue<pi, vector<pi>, greater<pi>> q; // Test if j can become the optimal next rope in the path from p[i] to M void test(int i, int j) { if (i < 0 || i >= N) { return; } if (abs(p[i] - p[j]) >= minlen[j] && abs(p[i] - p[j]) < minlen[i]) { minlen[i] = abs(p[i] - p[j]); nxt[i] = j; q.push(mp(minlen[i], i)); } } void init(int n, int m, int P[]){ N = n; M = m; p.resize(N); minlen.resize(N); nxt.resize(N); for (int i = 0; i < N; i++) { p[i] = P[i]; } sort(p.begin(), p.end()); for (int i = 0; i < N; i++) { minlen[i] = M - p[i]; nxt[i] = N; q.push(mp(minlen[i], i)); } while (!q.empty()) { int i, d; tie(d, i) = q.top(); q.pop(); if (minlen[i] < d) { continue; } // Advance nxt[i] int j; if (nxt[i] < i) { j = i + 1; } else { j = i - 1; } test(j, nxt[i]); // Advance i int p_l = upper_bound(p.begin(), p.end(), p[i] - minlen[i]) - p.begin() - 1; int p_r = lower_bound(p.begin(), p.end(), p[i] + minlen[i]) - p.begin(); test(p_l, i); test(p_r, i); } } int minLength(int D) { int ans = M - D; for (int i = 0; i < N; i++) { if (abs(D - p[i]) >= minlen[i]) { ans = min(ans, abs(D - p[i])); } } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 3536 KB | Output is correct |
2 | Correct | 43 ms | 4052 KB | Output is correct |
3 | Correct | 39 ms | 3792 KB | Output is correct |
4 | Correct | 43 ms | 3792 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 3536 KB | Output is correct |
2 | Correct | 43 ms | 4052 KB | Output is correct |
3 | Correct | 39 ms | 3792 KB | Output is correct |
4 | Correct | 43 ms | 3792 KB | Output is correct |
5 | Incorrect | 0 ms | 344 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 3536 KB | Output is correct |
2 | Correct | 43 ms | 4052 KB | Output is correct |
3 | Correct | 39 ms | 3792 KB | Output is correct |
4 | Correct | 43 ms | 3792 KB | Output is correct |
5 | Incorrect | 0 ms | 344 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |