답안 #55030

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55030 2018-07-05T21:32:56 Z luciocf 구경하기 (JOI13_watching) C++14
0 / 100
5 ms 988 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e3+10;

int num[MAXN], n, a, b;

bool ok(int w)
{
    int p = a, q = b;
    for (int i = 1; i <= n; i++)
    {
        if (!p && !q) return false;
        int pos = n, pos2 = n;
        for (int j = i+1; j <= n; j++)
        {
            if (num[i]+2*w-1 < num[j])
            {
                pos = j-1;
                break;
            }
        }

        if (!p)
        {
            i = pos;
            q--;
            continue;
        }

        for (int j = i+1; j <= n; j++)
        {
            if (num[i]+w-1 < num[j])
            {
                pos2 = j-1;
                break;
            }
        }

        if (!q)
        {
            i = pos2;
            p--;
            continue;
        }

        if (pos > pos2)
        {
            q--;
            i = pos;
        }
        else
        {
            p--;
            i = pos2;
        }
    }
    return true;
}

int busca(void)
{
    int ini = 1, fim = 1e9;
    while (ini < fim)
    {
        int mid = (ini+fim)/2;

        if (ok(mid)) fim = mid;
        else ini = mid+1;
    }
    return fim;
}

int main(void)
{
    cin >> n >> a >> b;

    for (int i = 1; i <= n; i++) cin >> num[i];

    sort(num+1, num+n+1);
    cout << busca() << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 624 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 2 ms 652 KB Output is correct
5 Correct 2 ms 704 KB Output is correct
6 Correct 4 ms 708 KB Output is correct
7 Incorrect 2 ms 716 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 776 KB Output is correct
2 Correct 2 ms 808 KB Output is correct
3 Correct 4 ms 832 KB Output is correct
4 Correct 3 ms 908 KB Output is correct
5 Correct 5 ms 908 KB Output is correct
6 Correct 5 ms 948 KB Output is correct
7 Incorrect 5 ms 988 KB Output isn't correct
8 Halted 0 ms 0 KB -