Submission #860549


Source Code Expand

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

#define MAX_N 100000

int tab[20][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;

	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<20; 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 1057 Byte
Status RE
Exec Time 230 ms
Memory 8448 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 4 ms 384 KB
subtask1_01.txt AC 4 ms 384 KB
subtask1_02.txt AC 4 ms 384 KB
subtask1_03.txt RE 188 ms 384 KB
subtask1_04.txt RE 189 ms 384 KB
subtask1_05.txt RE 189 ms 384 KB
subtask1_06.txt AC 8 ms 384 KB
subtask1_07.txt AC 7 ms 384 KB
subtask1_08.txt RE 189 ms 384 KB
subtask1_09.txt RE 189 ms 384 KB
subtask1_10.txt RE 187 ms 384 KB
subtask1_11.txt RE 190 ms 384 KB
subtask1_12.txt RE 188 ms 384 KB
subtask1_13.txt RE 189 ms 384 KB
subtask2_01.txt RE 224 ms 8448 KB
subtask2_02.txt RE 229 ms 8448 KB
subtask2_03.txt RE 228 ms 8448 KB
subtask2_04.txt RE 211 ms 5760 KB
subtask2_05.txt RE 213 ms 5760 KB
subtask2_06.txt RE 225 ms 8448 KB
subtask2_07.txt RE 228 ms 8448 KB
subtask2_08.txt RE 228 ms 8448 KB
subtask2_09.txt RE 227 ms 8448 KB
subtask2_10.txt RE 229 ms 8448 KB
subtask2_11.txt RE 226 ms 7936 KB
subtask2_12.txt RE 230 ms 8448 KB
subtask2_13.txt RE 226 ms 8448 KB