답안 #187531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
187531 2020-01-13T02:39:08 Z dndhk 구경하기 (JOI13_watching) C++14
50 / 100
1000 ms 18680 KB
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N = 2000;
const ll INFLL = 10000;
int N, P, Q;
vector<ll> v;

int dp[MAX_N+1][MAX_N+1];

int lb(ll x){
	//cout<<"?"<<x<<" ";
	int s = 1, e = v.size()-1, m;
	while(s<e){
		m = (s+e)/2+1;
		//cout<<m<<" "<<v[m]<<endl;

		if(v[m]<=x)	s = m;
		else	e = m-1;
	}
	//cout<<s<<endl;
	return s;
}

deque<pii> dq[2][MAX_N+1];

void add(int idx, int x, int y, int z){
	while(!dq[idx][x].empty() && dq[idx][x].back().first>=z){
		dq[idx][x].pop_back();
	}
	dq[idx][x].push_back({z, y});
}

bool chk(ll x){
	for(int i=0; i<=N; i++){
		for(int j=0; j<=N; j++)	dp[i][j] = INFLL;
		while(!dq[0][i].empty())	dq[0][i].pop_back();
		while(!dq[1][i].empty())	dq[1][i].pop_back();
	}
	dp[0][0] = 0LL;
	//cout<<x<<endl;
	for(int i=0; i<=N; i++){
		for(int j=N; j>=0; j--){
			while(!dq[0][j].empty() && dq[0][j].front().second<i)	dq[0][j].pop_front();
			while(!dq[1][j].empty() && dq[1][j].front().second<i)	dq[1][j].pop_front();
			if(dq[0][j].empty()){
				if(!dq[1][j].empty())	dp[i][j] = dq[1][j].front().first;
			}else{
				if(dq[1][j].empty())	dp[i][j] = dq[0][j].front().first;
				else{
					dp[i][j] = min(dq[0][j].front().first, dq[1][j].front().first);
				}
			}
			//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
			if(dp[i][j]==INFLL || i==N)	continue;
			int k = dp[i][j];
			int r1 = lb(v[i+1]+x-1LL), r2 = lb(v[i+1]+2LL*x-1LL);
			add(0, j+1, r1, k);
			add(1, j, r2, k+1);
		}
	}
	for(int i=0; i<=P; i++){
		if(dp[N][i]<=Q)	return true;
	}
	return false;
}

int main(){
	scanf("%d%d%d", &N, &P, &Q);	
	v.pb(0);
	for(int i=1; i<=N; i++){
		ll x; scanf("%lld", &x);
		v.pb(x);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	N = v.size()-1;
	ll s = 1LL, e = 1000000000LL, m;
	while(s<e){
		m = (s+e)/2LL;
		if(chk(m)){
			e = m;
		}else{
			s = m+1;
		}
	}
	printf("%lld", s);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &P, &Q); 
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   ll x; scanf("%lld", &x);
         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 3576 KB Output is correct
2 Correct 5 ms 3064 KB Output is correct
3 Correct 4 ms 3064 KB Output is correct
4 Correct 13 ms 3624 KB Output is correct
5 Correct 15 ms 3452 KB Output is correct
6 Correct 17 ms 3320 KB Output is correct
7 Correct 14 ms 3448 KB Output is correct
8 Correct 13 ms 3420 KB Output is correct
9 Correct 15 ms 3448 KB Output is correct
10 Correct 15 ms 3448 KB Output is correct
11 Correct 15 ms 3576 KB Output is correct
12 Correct 17 ms 3576 KB Output is correct
13 Correct 13 ms 3448 KB Output is correct
14 Correct 12 ms 3448 KB Output is correct
15 Correct 14 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 18680 KB Time limit exceeded
2 Halted 0 ms 0 KB -