답안 #670836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670836 2022-12-10T19:45:20 Z finn__ Circus (Balkan15_CIRCUS) C++17
0 / 100
17 ms 2888 KB
#include "circus.h"
#include <bits/stdc++.h>
using namespace std;

vector<int64_t> p;
vector<int64_t> dp;
int64_t m;

int64_t min_height(int64_t d)
{
    int64_t a = 0, b = 1e18;

    while (a < b)
    {
        int64_t mid = (a + b) / 2;

        size_t i = upper_bound(p.begin(), p.end(), d) - p.begin() - 1;
        bool possible = 0;
        while (i < p.size() && p[i] <= d + mid && !possible)
        {
            if (dp[i] <= p[i] - d)
                possible = 1;
            i++;
        }

        if (possible)
            b = mid;
        else
            a = mid + 1;
    }

    return a;
}

void init(int N, int M, int P[])
{
    m = M;
    p = vector<int64_t>(N + 1);
    dp = vector<int64_t>(N + 1);
    p[N] = M;
    dp[N] = 0;
    copy(P, P + N, p.begin());
    sort(p.begin(), p.end());

    for (size_t i = 0; i < N + 1; i++)
        dp[i] = max((int64_t)0, M - p[i]);

    priority_queue<pair<int64_t, unsigned>, vector<pair<int64_t, unsigned>>, greater<pair<int64_t, unsigned>>> q;
    q.push({0, lower_bound(p.begin(), p.end(), M) - p.begin()});

    while (!q.empty())
    {
        auto const [h, u] = q.top();
        q.pop();

        if (h != dp[u])
            continue;

        size_t i = upper_bound(p.begin(), p.end(), p[u] + h) - p.begin();

        while (i < p.size())
        {
            if (p[i] - p[u] < dp[i])
            {
                dp[i] = p[i] - p[u];
                q.push({dp[i], i});
            }
            i++;
        }

        i = upper_bound(p.begin(), p.end(), p[u] - h) - p.begin() - 1;

        while (i <= N)
        {
            if (p[u] - p[i] < dp[i])
            {
                dp[i] = p[u] - p[i];
                q.push({dp[i], i});
            }
            i--;
        }
    }
}

int minLength(int D)
{
    int64_t min_h = m - D;
    for (size_t i = 0; i < dp.size(); i++)
        if (dp[i] <= abs(D - p[i]))
            min_h = min(min_h, abs(D - p[i]));
    return min_h;
}

Compilation message

circus.cpp: In function 'void init(int, int, int*)':
circus.cpp:45:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |     for (size_t i = 0; i < N + 1; i++)
      |                        ~~^~~~~~~
circus.cpp:73:18: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   73 |         while (i <= N)
      |                ~~^~~~
grader.cpp: In function 'int main()':
grader.cpp:14:12: warning: unused variable 'max_code' [-Wunused-variable]
   14 |  long long max_code;
      |            ^~~~~~~~
grader.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
grader.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   scanf("%d", &P[i]);
      |   ~~~~~^~~~~~~~~~~~~
grader.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
grader.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   scanf("%d", &d);
      |   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 2888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 2888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 2888 KB Output isn't correct
2 Halted 0 ms 0 KB -