Submission #465010

# Submission time Handle Problem Language Result Execution time Memory
465010 2021-08-14T20:29:21 Z Hamed5001 Watching (JOI13_watching) C++14
0 / 100
4 ms 588 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define gen(arr,n,nxt)  generate(arr,arr+n,nxt)
#define Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0);
 
const int mo=1e9+7,INF=1e18;
int nxt(){int x;cin>>x;return x;}
int n,sm,big,arr[2001],dp[2001][2001],mid;

int check(int idx,int small){
	if (small < 0) return 1e10;
	if (idx == -1) return 0;

	int &ret = dp[idx][small];
	if (~ret) return ret;
	int idx1 = idx, idx2 = idx;
	while(idx1 >= 0 && arr[idx] - arr[idx1] < mid)
		idx1--;
	while(idx2 >= 0 && arr[idx] - arr[idx2] < 2*mid)
		idx2--;
	return ret = min(check(idx1, small-1), check(idx2, small)+1);
}
 
bool ok(){
    memset(dp,-1,sizeof dp);
    for (int i = 0; i <= sm; i++) {
    	check(n-1, i);
    }
    for (int i = 0; i <= sm; i++) {
    	if (dp[n-1][i] <= big)
    		return 1;
    }
    return 0;
}
signed main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty
    n=nxt(),sm=nxt(),big=nxt();

    if(n<big)big=n;
    if(n<sm)sm=n;

    gen(arr,n,nxt);
    sort(arr,arr+n);

    mid = 2;
    int s=0,e=1e9,mn=1e9;
    while(s<=e){
        if(e==1)break;
        mid=(s+e)>>1;
        if(ok()){
            mn=min(mn,mid);
            e=mid-1;
        }
        else s=mid+1;
    }
    cout<<mn;
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  freopen("input.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:42:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  freopen("output.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -