Submission #25405

# Submission time Handle Problem Language Result Execution time Memory
25405 2017-06-22T04:41:33 Z 도토리(#1071) Watching (JOI13_watching) C++14
100 / 100
813 ms 18468 KB
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 15;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

ll in[2050];
int nxt[2][2050];

int dp[2050][2050];
int main() {
	int N, P, Q, i, j;
	scanf("%d %d %d", &N, &P, &Q);
	P = min(P, N);
	Q = min(Q, N);
	for (i = 1; i <= N; i++) scanf("%lld", &in[i]);
	sort(in + 1, in + N + 1);
	N = unique(in + 1, in + N + 1) - (in + 1);

	ll st = 1, en = INF, mi, rv = en + 1;
	while (st <= en) {
		mi = (st + en) / 2;
		
		nxt[0][N + 1] = nxt[1][N + 1] = N;
		for (i = 1; i <= N; i++) {
			nxt[0][i] = lower_bound(in + 1, in + N + 1, in[i] + mi) - in - 1;
			nxt[1][i] = lower_bound(in + 1, in + N + 1, in[i] + 2 * mi) - in - 1;
		}

		dp[0][0] = 0;
		for (i = 0; i <= P; i++) {
			for (j = 0; j <= Q; j++) {
				dp[i][j] = 0;
				if (i) dp[i][j] = max(dp[i][j], nxt[0][dp[i - 1][j] + 1]);
				if (j) dp[i][j] = max(dp[i][j], nxt[1][dp[i][j - 1] + 1]);
			}
		}
		if (dp[P][Q] == N) {
			rv = mi;
			en = mi - 1;
		}
		else st = mi + 1;
	}
	return !printf("%lld\n", rv);
}

Compilation message

watching.cpp:23:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)  
 ^
watching.cpp:24:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:336777216")  
 ^
watching.cpp: In function 'int main()':
watching.cpp:59:31: 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:62:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 1; i <= N; i++) scanf("%lld", &in[i]);
                                                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 18468 KB Output is correct
2 Correct 0 ms 18468 KB Output is correct
3 Correct 0 ms 18468 KB Output is correct
4 Correct 0 ms 18468 KB Output is correct
5 Correct 0 ms 18468 KB Output is correct
6 Correct 3 ms 18468 KB Output is correct
7 Correct 0 ms 18468 KB Output is correct
8 Correct 0 ms 18468 KB Output is correct
9 Correct 0 ms 18468 KB Output is correct
10 Correct 0 ms 18468 KB Output is correct
11 Correct 0 ms 18468 KB Output is correct
12 Correct 0 ms 18468 KB Output is correct
13 Correct 0 ms 18468 KB Output is correct
14 Correct 0 ms 18468 KB Output is correct
15 Correct 0 ms 18468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18468 KB Output is correct
2 Correct 0 ms 18468 KB Output is correct
3 Correct 463 ms 18468 KB Output is correct
4 Correct 43 ms 18468 KB Output is correct
5 Correct 39 ms 18468 KB Output is correct
6 Correct 813 ms 18468 KB Output is correct
7 Correct 3 ms 18468 KB Output is correct
8 Correct 19 ms 18468 KB Output is correct
9 Correct 23 ms 18468 KB Output is correct
10 Correct 39 ms 18468 KB Output is correct
11 Correct 39 ms 18468 KB Output is correct
12 Correct 196 ms 18468 KB Output is correct
13 Correct 6 ms 18468 KB Output is correct
14 Correct 6 ms 18468 KB Output is correct
15 Correct 6 ms 18468 KB Output is correct