답안 #466514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466514 2021-08-19T14:23:24 Z stefantaga 구경하기 (JOI13_watching) C++14
0 / 100
1000 ms 31600 KB
#include <bits/stdc++.h>
#define INF 100000000
using namespace std;
pair <int,int> din[2005][2005];
int n,mici,mari,v[2005],st,dr,mij,i,sol;
bool verif (int val)
{
    int i,j,lung,dr;
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            din[i][j]={INF,INF};
        }
    }
    for (lung=1;lung<=n;lung++)
    {
        for (i=1;i<=n-lung+1;i++)
        {
            dr=i+lung-1;
            din[i][dr]={INF,INF};
            if (v[dr]-v[i]+1<=val)
            {
                if (mici!=0)
                {
                    din[i][dr]=min(din[i][dr],{0,1});
                }
            }
            if (v[dr]-v[i]+1<=2*val)
            {
                if (mari!=0)
                {
                    din[i][dr]=min(din[i][st],{1,0});
                }
            }
            for (j=i;j<=dr-1;j++)
            {
                if (din[i][j].first+din[j+1][dr].first<=mici&&din[i][j].second+din[j+1][dr].second<=mari)
                {
                    din[i][dr]=min(din[i][dr],{din[i][j].second+din[j+1][dr].second,din[i][j].first+din[j+1][dr].first});
                }
            }
        }
    }
    if (din[1][n].first!=INF&&din[1][n].second!=INF)
    {
            return 1;
    }
    return 0;
}
int main()
{
    #ifdef HOME
    ifstream cin("date.in");
    ofstream cout("date.out");
    #endif // HOME
    cin>>n>>mici>>mari;
    for (i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    sort (v+1,v+n+1);
    st=1;
    dr=1000000000;
    while (st<=dr)
    {
        mij=(st+dr)/2;
        if (verif(mij)==1)
        {
            sol=mij;
            dr=mij-1;
        }
        else
        {
            st=mij+1;
        }
    }
    cout<<sol;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 1356 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1074 ms 31600 KB Time limit exceeded
2 Halted 0 ms 0 KB -