# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1047397 | 2024-08-07T12:28:59 Z | PanosPask | Circus (Balkan15_CIRCUS) | C++14 | 30 ms | 2396 KB |
#include <bits/stdc++.h> #include "circus.h" #define mp make_pair using namespace std; const int INF = 1e9 + 1; 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.assign(N, INF); nxt.resize(N); for (int i = 0; i < N; i++) { p[i] = P[i]; } sort(p.begin(), p.end()); p.push_back(M); minlen.push_back(0); nxt.push_back(N); q.push(mp(0, N)); 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 | 30 ms | 2392 KB | Output is correct |
2 | Correct | 30 ms | 2372 KB | Output is correct |
3 | Correct | 30 ms | 2368 KB | Output is correct |
4 | Correct | 30 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 2392 KB | Output is correct |
2 | Correct | 30 ms | 2372 KB | Output is correct |
3 | Correct | 30 ms | 2368 KB | Output is correct |
4 | Correct | 30 ms | 2396 KB | Output is correct |
5 | Incorrect | 0 ms | 348 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 2392 KB | Output is correct |
2 | Correct | 30 ms | 2372 KB | Output is correct |
3 | Correct | 30 ms | 2368 KB | Output is correct |
4 | Correct | 30 ms | 2396 KB | Output is correct |
5 | Incorrect | 0 ms | 348 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |