Submission #860546


Source Code Expand

Copy
#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_N 100000

int tab[40][MAX_N];

// mid日でaからbまで行けるか
bool C(int a, int b, int mid){
	int pos = a;
	int cnt = 0;
	while(mid != 0){
		if(mid & 1){
			pos = tab[cnt][pos];
		}
		mid >>= 1;
		cnt++;
	}
	if(pos >= b) return true;
	else return false;
}


int solve(int a, int b){
	if(a > b) swap(a, b);

	int ub = 100000;
	int lb = 0;
	while(ub - lb > 1){
		int mid = lb + (ub - lb) / 2;
		if(C(a, b, mid)) ub = mid;
		else lb = mid;
	}
	return ub;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, L, Q;
	int x[MAX_N];

	cin >> N;
	for(int i=0; i<N; i++) cin >> x[i];
	cin >> L >> Q;


	int y[MAX_N];

	for(int i=0; i<N; i++){
		tab[0][i]  = upper_bound(x, x+N, x[i]+L) - x - 1;
	}

	for(int k=0; k<40; k++){
		for(int i=0; i<N; i++){
			tab[k+1][i] = tab[k][min(N-1, tab[k][i])];
		}
	}

	for(int i=0; i<Q; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		cout << solve(a, b) << endl;
	}

	return 0;
}

Submission Info

Submission Time
Task E - Tak and Hotels
User suzume
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1077 Byte
Status RE
Exec Time 250 ms
Memory 16256 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 500
Status
AC × 1
AC × 5
RE × 9
AC × 5
RE × 22
Set Name Test Cases
Sample example_01.txt
Subtask1 example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt
All example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt
Case Name Status Exec Time Memory
example_01.txt AC 5 ms 384 KB
subtask1_01.txt AC 5 ms 384 KB
subtask1_02.txt AC 4 ms 384 KB
subtask1_03.txt RE 189 ms 640 KB
subtask1_04.txt RE 188 ms 640 KB
subtask1_05.txt RE 189 ms 640 KB
subtask1_06.txt AC 8 ms 512 KB
subtask1_07.txt AC 8 ms 512 KB
subtask1_08.txt RE 189 ms 640 KB
subtask1_09.txt RE 188 ms 640 KB
subtask1_10.txt RE 189 ms 640 KB
subtask1_11.txt RE 189 ms 640 KB
subtask1_12.txt RE 192 ms 640 KB
subtask1_13.txt RE 191 ms 640 KB
subtask2_01.txt RE 243 ms 16256 KB
subtask2_02.txt RE 250 ms 16256 KB
subtask2_03.txt RE 244 ms 16256 KB
subtask2_04.txt RE 222 ms 10880 KB
subtask2_05.txt RE 231 ms 10880 KB
subtask2_06.txt RE 246 ms 16256 KB
subtask2_07.txt RE 246 ms 16256 KB
subtask2_08.txt RE 243 ms 16256 KB
subtask2_09.txt RE 240 ms 16256 KB
subtask2_10.txt RE 244 ms 16256 KB
subtask2_11.txt RE 238 ms 15232 KB
subtask2_12.txt RE 243 ms 16256 KB
subtask2_13.txt RE 239 ms 16256 KB