답안 #68310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68310 2018-08-16T15:33:14 Z thebes 구경하기 (JOI13_watching) C++14
50 / 100
442 ms 32380 KB
#include <bits/stdc++.h>
using namespace std;

const int MN = 2002;
int pos[MN], N, P, Q, i, lo, hi, l, r, k, nxt[MN], nxt2[MN], dp[MN][MN];
int solve(int n,int rem){
	if(n == N+1) return 0;
	else if(dp[n][rem]!=-1) return dp[n][rem];
	if(rem) dp[n][rem]=min(solve(nxt[n],rem-1),solve(nxt2[n],rem)+1);
	else dp[n][rem]=solve(nxt2[n],rem)+1;
	return dp[n][rem];
}
bool check(int w){
	for(l=r=k=1;l<=N;l++){
		while(r<=N&&pos[r]-w+1<=pos[l]) r++;
		while(k<=N&&pos[k]-2*w+1<=pos[l]) k++;
		nxt[l] = r; nxt2[l] = k;
	}
	memset(dp, -1, sizeof(dp));
	return solve(1,P)<=Q;
}
int main(){
	for(scanf("%d%d%d",&N,&P,&Q),i=1;i<=N;i++)
		scanf("%d",&pos[i]);
	sort(pos+1,pos+N+1);
	lo = 1, hi = 1e9+7;
	while(lo < hi){
		int m = lo+hi>>1;
		if(check(m)) hi=m;
		else lo=m+1;
	}
	printf("%d\n",hi);
	return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:28:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = lo+hi>>1;
           ~~^~~
watching.cpp:23:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(scanf("%d%d%d",&N,&P,&Q),i=1;i<=N;i++)
      ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
watching.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&pos[i]);
   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 15992 KB Output is correct
2 Correct 91 ms 16168 KB Output is correct
3 Correct 89 ms 16212 KB Output is correct
4 Correct 84 ms 16400 KB Output is correct
5 Correct 83 ms 16400 KB Output is correct
6 Correct 84 ms 16400 KB Output is correct
7 Correct 76 ms 16400 KB Output is correct
8 Correct 85 ms 16400 KB Output is correct
9 Correct 87 ms 16400 KB Output is correct
10 Correct 94 ms 16400 KB Output is correct
11 Correct 88 ms 16400 KB Output is correct
12 Correct 89 ms 16400 KB Output is correct
13 Correct 81 ms 16400 KB Output is correct
14 Correct 84 ms 16440 KB Output is correct
15 Correct 87 ms 16440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 16440 KB Output is correct
2 Correct 90 ms 16524 KB Output is correct
3 Correct 442 ms 16656 KB Output is correct
4 Runtime error 42 ms 32380 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -