답안 #1001980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001980 2024-06-19T08:57:16 Z vjudge1 구경하기 (JOI13_watching) C++14
0 / 100
148 ms 262144 KB
#pragma GCC optimize("O3", "inline")
#include <bits/stdc++.h>
using namespace std;
#define ins insert
#define pb push_back
#define int long long int
#define pii pair<int, int>
#define endl '\n'
#define drop(x) cout<<(x)<<endl; return;
#define all(x) x.begin(),x.end()
const int   prime = 23,inf = 2e18,mod = 1e9 +7,sze =1e6;

struct node{
    int qalanbalaca;
    int qalanboyuk;
    int maxgedir;
};

int mx[50][2000][2000];
void mal(){
    int n,p,q;
    cin>>n>>p>>q;
    vector<int> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(all(arr));
    memset(mx, -1,sizeof mx);
    int l = 1;
    int r = 1e9;
    int ans=r;
    int lg =0;
    while(l<=r){
        lg++;
        int mid = (l+r)/2;
        int w = mid-1;
        int bigw = mid*2 -1;
        bool check=false;
        int tmx =0;
        
        for(int j=0;j<=min(n,p);j++){
            for(int k=0;k<=min(n,q);k++){   
                if(j || k){
                    if(j){
                        int y = mx[lg][j-1][k];
                        int i = y+1;
                        // yeni p kullanicam
                        if(y>=i-1){
                            int yer = (--upper_bound(all(arr),arr[i] + w)) - arr.begin();
                            mx[lg][j][k]= max(mx[lg][j][k],yer);
                            tmx=max(tmx,mx[lg][j][k]);
                        }
                    }
                    if(k){
                        int y = mx[lg][j][k-1];
                        int i = y+1;
                        if(y>=i-1){
                            int yer = (--upper_bound(all(arr),arr[i]+bigw)) - arr.begin();
                            mx[lg][j][k]=max(mx[lg][j][k],yer);
                            tmx=max(tmx,mx[lg][j][k]);
                        }
                    }
                }
            }
        }
    
        if(tmx>=n-1){
            check=true;
        }
        
        /*
            i ci yere qeder j dene small, k dene big kullanildi
        */
 
        if(check){
            // cout<<mid<<" "<<w<<" "<<bigw<<endl;
            r=mid-1;
            ans=mid;
        }
        else{
            l=mid+1;
        }

    }
    drop(ans);
}   

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int tt = 1;
    // cin>>tt;
    
    while(tt--){
        mal();        
    }
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 145 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 148 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -