답안 #760563

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760563 2023-06-17T19:05:33 Z HibaKhalil 구경하기 (JOI13_watching) C++14
0 / 100
1000 ms 340 KB
#include <bits/stdc++.h>
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pii pair<int,int>
#define ppb pop_back()
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
using namespace std;
/*int tx[4] = {0,0,1,-1};
int ty[4] = {1,-1,0,0};
char t[4] = {'R','L','D','U'};
*/
int n,p,q;
vector<int> v;
bool process(int pos,int w, int np,int nq)
{
    if(pos==n) return 1;
    if(np==p && nq==q) return 0;
    //w
    bool res1=0, res2=0;
    if(np<p)
    {
        int curr = w+v[pos]-1;
        int l=pos,r=n;
        while(l+1<r)
        {
            int mid = (l+r)/2;
            if(curr<v[mid])
                r=mid;
            else l=mid;
        }
        res1 = process(r,w,np+1,nq);
    }

    //2w
    if(nq<q)
    {
        int curr = 2*w+v[pos]-1;
        int l=pos,r=n;
        while(l+1<r)
        {
            int mid = (l+r)/2;
            if(curr<v[mid])
                r=mid;
            else l=mid;
        }
        res2 = process(r,w,np,nq+1);
    }

    return res1 || res2;
}
bool good(int w)
{
   // cout<<w<<" "<<process(0,w,0,0)<<endl;
    return process(0,w,0,0);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    scanf("%d %d %d",&n,&p,&q);
    r(i,n)
    {
        int ev;
        scanf("%d",&ev);
        v.pb(ev);
    }
    sort(v.begin(),v.end());

    int l=0,r=(int)1e9; // r is true , l is false
    while(l+1<r)
    {
        int m = (l+r)/2;
        if(good(m))
        {
            r=m;
        }
        else
        {
            l=m;
        }
    }

    printf("%d\n",r);

    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%d %d %d",&n,&p,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
watching.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%d",&ev);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 1073 ms 212 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1075 ms 212 KB Time limit exceeded
4 Halted 0 ms 0 KB -